Skip to content

Commit a286b18

Browse files
[css-overflow-5] Add :target-before and :target-after pseudo classes w3c#11600 (w3c#12662)
* [css-overflow-5] Add :target-before and :target-after pseudo classes w3c#11600
1 parent 6180d79 commit a286b18

File tree

1 file changed

+49
-8
lines changed

1 file changed

+49
-8
lines changed

css-overflow-5/Overview.bs

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -366,21 +366,62 @@ The 'scroll-marker-group' property</h4>
366366
or via the tab key when currently active or when no other ''::scroll-marker'' is active and this is the first marker in the group,
367367
ensuring the group has a <a href="https://open-ui.org/components/focusgroup.explainer/#guaranteed-tab-stop">guaranteed tab stop</a>.
368368

369-
<h4 id="active-scroll-marker">
370-
Selecting The Active Scroll Marker: the '':target-current'' pseudo-class</h4>
369+
<h4 id="active-before-after-scroll-markers">
370+
Selecting Scroll Markers: '':target-current'', '':target-before'' and '':target-after'' pseudo-classes</h4>
371371

372372
Exactly one [=scroll marker=] within each [=scroll marker group=] is determined to be active at a time.
373373
Such "active" [=scroll markers=] match the <dfn selector>:target-current</dfn> pseudo-class.
374374

375-
<div class='example'>
376-
The following snippet shows how the link to the currently scrolled section can be highlighted:
375+
In addition to the <a>:target-current</a> pseudo-class, this specification introduces the <dfn selector>:target-before</dfn> and <dfn selector>:target-after</dfn> pseudo-classes for use with [=scroll marker=] elements.
376+
377+
These pseudo-classes match [=scroll marker=]s that are, respectively, before or after the [=active marker=] (the one matching <a>:target-current</a>) within the same [=scroll marker group=], as determined by [=flat tree order=]:
378+
379+
- <b>:target-before</b> matches all [=scroll marker=]s that precede the [=active marker=] in the flat tree order within the group.
380+
- <b>:target-after</b> matches all [=scroll marker=]s that follow the [=active marker=] in the flat tree order within the group.
377381

378-
<pre highlight=css>
382+
<div class='example'>
383+
The following snippet demonstrates how to style the active scroll marker and scroll markers before and after the currently active one in a table of contents:
384+
385+
<pre><code highlight="html">
386+
&lt;!DOCTYPE HTML&gt;
387+
&lt;title&gt;:target-before and :target-after example&lt;/title&gt;
388+
&lt;style&gt;
389+
ol {
390+
background-color: gray;
391+
right: 10px;
392+
top: 10px;
393+
position: fixed;
394+
scroll-target-group: auto;
395+
}
396+
a:target-before {
397+
color: #888;
398+
}
379399
a:target-current {
400+
color: red;
380401
font-weight: bold;
381402
}
382-
</pre>
383-
</div>
403+
a:target-after {
404+
color: #444;
405+
}
406+
.chapter {
407+
background: lightgray;
408+
height: 60vh;
409+
margin: 10px;
410+
}
411+
&lt;/style&gt;
412+
&lt;ol&gt;
413+
&lt;li&gt;&lt;a href="#intro"&gt;Introduction&lt;/a&gt;&lt;/li&gt;
414+
&lt;li&gt;&lt;a href="#ch1"&gt;Chapter 1&lt;/a&gt;&lt;/li&gt;
415+
&lt;li&gt;&lt;a href="#ch2"&gt;Chapter 2&lt;/a&gt;&lt;/li&gt;
416+
&lt;/ol&gt;
417+
&lt;div id="intro" class="chapter"&gt;Introduction content&lt;/div&gt;
418+
&lt;div id="ch1" class="chapter"&gt;Chapter 1 content&lt;/div&gt;
419+
&lt;div id="ch2" class="chapter"&gt;Chapter 2 content&lt;/div&gt;
420+
</code></pre>
421+
</div>
422+
423+
<h4 id="active-scroll-markers-calculation">
424+
Calculating the Active Scroll Marker</h4>
384425

385426
A scrolling operation might animate towards a particular position
386427
(e.g. scrollbar arrow clicks, arrow key presses, "behavior: smooth" programmatic scrolls)
@@ -456,7 +497,7 @@ Selecting The Active Scroll Marker: the '':target-current'' pseudo-class</h4>
456497
Focus |active marker|
457498
1. Set the <a href="https://open-ui.org/components/focusgroup.explainer/#last-focused-memory">last-focused element</a> of the |group| to |active marker|.
458499
1. Set the active state of all other [=scroll marker=] elements in |group| to false.
459-
</div>
500+
</div>
460501

461502
<h4 id="scroll-marker-activation">Activation behavior</h4>
462503

0 commit comments

Comments
 (0)