Skip to content

Commit c6e02b5

Browse files
bsmthestelle
andauthored
chore(css): Move CSS examples - Feature queries, overflow, subgrid, masonry (mdn#36693)
* chore(css): Move CSS examples - Using feature queries * chore(css): Move CSS examples - Flow layout and overflow * chore(css): Move CSS examples - Flow layout and overflow * chore(css): Move CSS examples - In flow and out of flow * chore(css): Move CSS examples - Masonry layout * chore(css): Move CSS examples - Subgrid * Apply suggestions from code review Co-authored-by: Estelle Weyl <[email protected]> * chore(css): Move CSS examples - Changes following reviewer feedback * Apply suggestions from code review Co-authored-by: Estelle Weyl <[email protected]> --------- Co-authored-by: Estelle Weyl <[email protected]>
1 parent 54c533b commit c6e02b5

File tree

6 files changed

+1414
-62
lines changed

6 files changed

+1414
-62
lines changed

files/en-us/web/css/css_conditional_rules/using_feature_queries/index.md

Lines changed: 108 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,31 @@ For example, we can apply a set of styles or import an entire stylesheet if the
4040

4141
As another example, if you want to check if a browser supports the `row-gap` property you would write the following feature query. It doesn't matter which value you use in a lot of cases: if all you want is to check that the browser supports this property, then any valid value will do.
4242

43-
{{EmbedGHLiveSample("css-examples/feature-queries/simple.html", '100%', 600)}}
43+
```html live-sample___simple
44+
<div class="box">
45+
If your browser supports the row-gap property, the border will be dashed and
46+
text will be red.
47+
</div>
48+
```
49+
50+
```css live-sample___simple
51+
body {
52+
font: 1.2em / 1.5 sans-serif;
53+
}
54+
.box {
55+
border: 4px solid blue;
56+
color: blue;
57+
padding: 1em;
58+
}
59+
@supports (row-gap: 10px) {
60+
.box {
61+
border: 4px dashed darkgreen;
62+
color: red;
63+
}
64+
}
65+
```
66+
67+
{{EmbedLiveSample("simple")}}
4468

4569
The value part of the property-value pair matters more if you are testing for new values of a particular property. All browsers support `color: red`: this dates back to CSS1. However, there are often additional values added to properties in CSS, like [relative colors](/en-US/docs/Web/CSS/CSS_colors/Relative_colors), which may not be supported. Feature queries enable testing property and value pairs, meaning we can detect support for values.
4670

@@ -71,7 +95,31 @@ In addition to asking the browser if it supports a feature, you can test for the
7195

7296
The CSS inside the following example feature query will run if the browser does not support `row-gap`.
7397

74-
{{EmbedGHLiveSample("css-examples/feature-queries/not.html", '100%', 600)}}
98+
```html live-sample___not
99+
<div class="box">
100+
If your browser does not support row-gap, the content will be darkgreen with a
101+
dashed border.
102+
</div>
103+
```
104+
105+
```css live-sample___not
106+
body {
107+
font: 1.2em / 1.5 sans-serif;
108+
}
109+
.box {
110+
border: 4px solid blue;
111+
color: blue;
112+
padding: 1em;
113+
}
114+
@supports not (row-gap: 10px) {
115+
.box {
116+
border: 4px dashed darkgreen;
117+
color: darkgreen;
118+
}
119+
}
120+
```
121+
122+
{{EmbedLiveSample("not")}}
75123

76124
## Testing for more than one feature
77125

@@ -86,7 +134,32 @@ You may need to test support for more than one property in your feature query. T
86134

87135
For example, if the CSS you want to run requires that the browser supports CSS Shapes and CSS grid, you could create a rule that tests browser support for both of these features. The following rule will only return true if `shape-outside: circle()` and `display: grid` are both supported by the browser.
88136

89-
{{EmbedGHLiveSample("css-examples/feature-queries/and.html", '100%', 600)}}
137+
```html live-sample___and
138+
<div class="box">
139+
If your browser supports <code>display: grid</code> and
140+
<code>shape-outside: circle()</code>, the content will be darkgreen with a
141+
dashed border.
142+
</div>
143+
```
144+
145+
```css live-sample___and
146+
body {
147+
font: 1.2em / 1.5 sans-serif;
148+
}
149+
.box {
150+
border: 4px solid blue;
151+
color: blue;
152+
padding: 1em;
153+
}
154+
@supports (display: grid) and (shape-outside: circle()) {
155+
.box {
156+
border: 4px dashed darkgreen;
157+
color: darkgreen;
158+
}
159+
}
160+
```
161+
162+
{{EmbedLiveSample("and")}}
90163

91164
## Testing for at least one of multiple features
92165

@@ -101,7 +174,30 @@ You can also use `or` to apply CSS only if one or more declarations are supporte
101174

102175
This can be particularly useful if a feature is vendor prefixed, as you can test for the standard property plus any vendor prefixes.
103176

104-
{{EmbedGHLiveSample("css-examples/feature-queries/or.html", '100%', 600)}}
177+
```html live-sample___or
178+
<div class="box">
179+
The text and border will be green if your browser supports font smoothing.
180+
</div>
181+
```
182+
183+
```css live-sample___or
184+
body {
185+
font: 1.2em / 1.5 sans-serif;
186+
}
187+
.box {
188+
border: 4px solid blue;
189+
color: blue;
190+
padding: 1em;
191+
}
192+
@supports (font-smooth: always) or (-webkit-font-smoothing: antialiased) {
193+
.box {
194+
border: 4px dashed darkgreen;
195+
color: darkgreen;
196+
}
197+
}
198+
```
199+
200+
{{EmbedLiveSample("or")}}
105201

106202
## Additional feature query options
107203

@@ -133,6 +229,12 @@ In this example, we check if the browser supports the `AccentColor` {{cssxref("s
133229
#### CSS
134230

135231
```css
232+
body {
233+
font: 1.2em / 1.5 sans-serif;
234+
}
235+
p {
236+
padding: 1em;
237+
}
136238
@supports (color: AccentColor) {
137239
p {
138240
color: green;
@@ -149,9 +251,9 @@ In this example, we check if the browser supports the `AccentColor` {{cssxref("s
149251
}
150252
```
151253

152-
#### Results
254+
#### Result
153255

154-
{{EmbedLiveSample("Browser support test", "600", "50")}}
256+
{{EmbedLiveSample("Browser support test")}}
155257

156258
## Limitations of feature queries
157259

0 commit comments

Comments
 (0)