Skip to content

Commit fbc343c

Browse files
committed
[css-nesting-1] initial idea for nested conditionals
1 parent aa42600 commit fbc343c

File tree

1 file changed

+60
-1
lines changed

1 file changed

+60
-1
lines changed

css-nesting-1/Overview.bs

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,64 @@ The Nesting At-Rule: ''@nest'' {#at-nest}
432432
</pre>
433433
</div>
434434

435+
Nesting Conditional Rules {#conditionals}
436+
-----------------------------------------------
437+
438+
A style rule can have any number of <a>conditional rules</a> inside of it, of any type,
439+
intermixed with any number of declarations, in any order.
440+
441+
The presence of a nested conditional engages the same logic as if ''@nest'' was present.
442+
The nested conditional rules must contain a <a>nesting selector</a> and follow the same
443+
rules as outlined in <a href="#direct">direct nesting</a>.
444+
445+
<div class="example">
446+
For example, the following conditional nestings are valid:
447+
448+
<pre class="lang-css">
449+
.foo {
450+
display: grid;
451+
452+
@media (orientation: landscape) {
453+
& {
454+
grid-auto-flow: column;
455+
}
456+
}
457+
}
458+
/* equivalent to
459+
.foo { display: grid; }
460+
461+
@media (orientation: portrait) {
462+
.foo {
463+
grid-auto-flow: column;
464+
}
465+
}
466+
*/
467+
</pre>
468+
469+
But the following are invalid:
470+
471+
<pre class=lang-css>
472+
.foo {
473+
display: grid;
474+
475+
@media (orientation: landscape) {
476+
grid-auto-flow: column;
477+
}
478+
}
479+
/* Invalid because there's no nesting selector */
480+
481+
.foo {
482+
color: red;
483+
484+
@media (min-width: 480px) {
485+
& h1, h2 { color: blue; }
486+
}
487+
}
488+
/* Invalid because not all selectors in the list
489+
contain a nesting selector */
490+
</pre>
491+
</div>
492+
435493
Mixing Nesting Rules and Declarations {#mixing}
436494
-----------------------------------------------
437495

@@ -440,7 +498,8 @@ Mixing Nesting Rules and Declarations {#mixing}
440498
intermixed with any number of declarations,
441499
in any order.
442500

443-
The relative ordering of <a>nested style rules</a> and other declarations <strong>is</strong> important;
501+
The relative ordering of <a>nested style rules</a>, <a>nested conditional rules</a> and
502+
other declarations <strong>is</strong> important;
444503
it's possible for a given style rule and a <a>nested style rule</a> within it to match the same element,
445504
and if the specificity of the two rules is otherwise equivalent,
446505
the relative order in the stylesheet of the applicable declarations

0 commit comments

Comments
 (0)