Skip to content

Commit 45f7907

Browse files
[css-pseudo-4] Add spec for resolving custom properties
In w3c#6641 it was resolved that "highlight pseudos inherit across the highlight tree, and the root highlight inherits custom props from the root element". Here we add spec language to explain the behavior.
1 parent 09cf7fb commit 45f7907

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

css-pseudo-4/Overview.bs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,49 @@ Cascading and Per-Element Highlight Styles</h3>
936936
css/css-pseudo/cascade-highlight-002.html
937937
</wpt>
938938

939+
<h4 id="highlight-custom-properties">
940+
Custom Properties in Highlight Styles</h3>
941+
942+
A [=custom property=] used in highlight styles uses the
943+
first custom property value found in the highlight cascade.
944+
However, if a custom property value cannot be resolved
945+
through the highlight cascade, the property value is taken from
946+
the root element.
947+
948+
<div class="example">
949+
For example, if an author specified
950+
<pre class="lang-css">
951+
:root {
952+
--background-color: green;
953+
--decoration-thickness: 10px;
954+
--decoration-color: purple;
955+
}
956+
::selection {
957+
--decoration-thickness: 1px;
958+
--decoration-color: green;
959+
}
960+
div::selection {
961+
--decoration-color: blue;
962+
background-color: var(--background-color, red);
963+
text-decoration-line: underline;
964+
text-decoration-style: line;
965+
text-decoration-thickness: var(--decoration-thickness, 5px);
966+
text-decoration-color: var(--decoration-color, red);
967+
}
968+
</pre>
969+
A div's selection highlight would be a green background to the
970+
selected content, with a 1px thick blue underline. The
971+
''--background-color'' custom property is not found on the
972+
''div::selection'' nor ''::selection'' so it is taken from the
973+
''::root'' custom property match. The ''--decoration-thickness''
974+
property is inherited from ''::selection'' via the highlight
975+
cascade and ''--decoration-color'' is found in
976+
''div::selection'' itself.
977+
</div>
978+
979+
This behavior is intended to accomodate the standard practice of
980+
defining document-wide custom properties on '':root''.
981+
939982
<h3 id="highlight-painting">
940983
Painting the Highlight</h3>
941984

0 commit comments

Comments
 (0)