Skip to content

Commit 7079222

Browse files
authored
Merge pull request w3c#5616 from w3c/css-nesting-1]-more-examples
2 parents 3b7e342 + bd03403 commit 7079222

File tree

1 file changed

+93
-15
lines changed

1 file changed

+93
-15
lines changed

css-nesting-1/Overview.bs

Lines changed: 93 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -203,27 +203,98 @@ Direct Nesting {#direct}
203203
& > .bar { color: red; }
204204
}
205205
/* equivalent to
206-
.foo { color: blue; }
207-
.foo > .bar { color: red; }
206+
.foo { color: blue; }
207+
.foo > .bar { color: red; }
208208
*/
209209

210210
.foo {
211211
color: blue;
212212
&.bar { color: red; }
213213
}
214214
/* equivalent to
215-
.foo { color: blue; }
216-
.foo.bar { color: red; }
215+
.foo { color: blue; }
216+
.foo.bar { color: red; }
217217
*/
218218

219219
.foo, .bar {
220220
color: blue;
221221
& + .baz, &.qux { color: red; }
222222
}
223223
/* equivalent to
224-
.foo, .bar { color: blue; }
225-
:is(.foo, .bar) + .baz,
226-
:is(.foo, .bar).qux { color: red; }
224+
.foo, .bar { color: blue; }
225+
:is(.foo, .bar) + .baz,
226+
:is(.foo, .bar).qux { color: red; }
227+
*/
228+
229+
.foo {
230+
color: blue;
231+
& .bar & .baz & .qux { color: red; }
232+
}
233+
/* equivalent to
234+
.foo { color: blue; }
235+
.foo .bar .foo .baz .foo .qux { color: blue; }
236+
*/
237+
238+
.foo {
239+
color: blue;
240+
& { padding: 2ch; }
241+
}
242+
/* equivalent to
243+
.foo { color: blue; }
244+
.foo { padding: 2ch; }
245+
246+
// and
247+
248+
.foo {
249+
color: blue;
250+
padding: 2ch;
251+
}
252+
*/
253+
254+
.error, #404 {
255+
&:not(.foo,.bar) > .baz { color: red; }
256+
}
257+
/* equivalent to
258+
:is(.error, #404):not(.foo,.bar) > .baz { color: red; }
259+
*/
260+
261+
.foo {
262+
&:is(.bar, &.baz) { color: red; }
263+
}
264+
/* equivalent to
265+
.foo:is(.bar, .foo.baz) { color: red; }
266+
*/
267+
268+
figure {
269+
margin: 0;
270+
271+
& > figcaption {
272+
background: hsl(0 0% 0% / 50%);
273+
274+
& > p {
275+
font-size: .9rem;
276+
}
277+
}
278+
}
279+
/* equivalent to
280+
figure { margin: 0; }
281+
figure > figcaption { background: hsl(0 0% 0% / 50%); }
282+
figure > figcaption > p { font-size: .9rem; }
283+
*/
284+
285+
main {
286+
& > section,
287+
& > article {
288+
background: white;
289+
290+
& > header {
291+
font-size: 1.25rem;
292+
}
293+
}
294+
}
295+
/* equivalent to
296+
main > :is(section, article) { background: white; }
297+
main > :is(section, article) > header { font-size: 1.25rem; }
227298
*/
228299
</pre>
229300

@@ -242,12 +313,19 @@ Direct Nesting {#direct}
242313
}
243314
/* Invalid because & isn't in the first compound selector */
244315

316+
.foo {
317+
color: red;
318+
&&.bar { color: blue; }
319+
}
320+
/* Invalid because the second & is no longer
321+
at the start of a compound selector */
322+
245323
.foo {
246324
color: red;
247325
&.bar, .baz { color: blue; }
248326
}
249327
/* Invalid because the second selector in the list doesn't
250-
contain a nesting selector. */
328+
contain a nesting selector. */
251329
</pre>
252330
</div>
253331

@@ -305,8 +383,8 @@ The Nesting At-Rule: ''@nest'' {#at-nest}
305383
}
306384
}
307385
/* equivalent to
308-
.foo { color: red; }
309-
.foo > .bar { color: blue; }
386+
.foo { color: red; }
387+
.foo > .bar { color: blue; }
310388
*/
311389

312390
.foo {
@@ -316,8 +394,8 @@ The Nesting At-Rule: ''@nest'' {#at-nest}
316394
}
317395
}
318396
/* equivalent to
319-
.foo { color: red; }
320-
.parent .foo { color: blue; }
397+
.foo { color: red; }
398+
.parent .foo { color: blue; }
321399
*/
322400

323401
.foo {
@@ -327,8 +405,8 @@ The Nesting At-Rule: ''@nest'' {#at-nest}
327405
}
328406
}
329407
/* equivalent to
330-
.foo { color: red; }
331-
:not(.foo) { color: blue; }
408+
.foo { color: red; }
409+
:not(.foo) { color: blue; }
332410
*/
333411
</pre>
334412

@@ -350,7 +428,7 @@ The Nesting At-Rule: ''@nest'' {#at-nest}
350428
}
351429
}
352430
/* Invalid because not all selectors in the list
353-
contain a nesting selector */
431+
contain a nesting selector */
354432
</pre>
355433
</div>
356434

0 commit comments

Comments
 (0)