Skip to content

Commit d25cffe

Browse files
committed
[css-pseudo] Improve examples of cascading.
1 parent 73deb7e commit d25cffe

File tree

2 files changed

+318
-202
lines changed

2 files changed

+318
-202
lines changed

css-pseudo/Overview.bs

+29-7
Original file line numberDiff line numberDiff line change
@@ -542,16 +542,17 @@ Cascading and Per-Element Highlight Styles</h3>
542542
<div class="example">
543543
For example, if the following rules were applied:
544544
<pre>
545-
p::selection { background: green; color: yellow; }
546-
em::selection { color: orange; }
545+
p::selection { color: yellow; background: green; }
546+
p > em::selection { color: orange; }
547+
em::selection { color: red; }
547548
</pre>
548549
to the following markup:
549550
<pre>
550-
&lt;p>Highlight this <em>and this</em>.&lt;/p>
551+
&lt;p>Highlight this &lt;em>and this&gt;/em>.&lt;/p>
551552
</pre>
552553
The highlight would be green throughout,
553-
with a yellow text outside the <code>&lt;em></code> element
554-
and a orange text inside it.
554+
with yellow text outside the <code>&lt;em></code> element
555+
and orange text inside it.
555556
</div>
556557

557558
Issue: This could alternately be described in terms of inheritance.
@@ -565,8 +566,29 @@ Cascading and Per-Element Highlight Styles</h3>
565566
<strong>'':root::selection''</strong>
566567
for their document-wide selection style,
567568
since this will allow clean overriding in descendants.
568-
(''::selection'' alone would apply to every element in the tree,
569-
overriding the more specific styles of any ancestors.)
569+
''::selection'' alone applies to every element in the tree,
570+
overriding the more specific styles of any ancestors.
571+
572+
<div class="example">
573+
For example, if an author specified
574+
<pre>
575+
::selection { background: blue; }
576+
p.warning { background: red; }
577+
</pre>
578+
and the document included
579+
<pre>
580+
&lt;p class="warning">Some &lt;strong>very important information&lt;/strong>&lt;/p>
581+
</pre>
582+
The highlight would be blue around “very important information”
583+
because the <code>&lt;strong></code> element´s ''::selection''
584+
also matches the ''::selection { background: blue; }'' rule.
585+
(Remember that ''*'' is implied when a tag selector is missing.)
586+
The style rules that would give the intended behavior are
587+
<pre>
588+
:root::selection { background: blue; }
589+
p.warning { background: red; }
590+
</pre>
591+
</div>
570592

571593
<h3 id="highlight-painting">
572594
Painting the Highlight</h3>

0 commit comments

Comments
 (0)