Skip to content

Commit eb4e1f7

Browse files
[css-overflow-5] Add an example for 'scroll-target-group' property (#12449)
As requested in Intent to Ship thread: https://groups.google.com/a/chromium.org/g/blink-dev/c/R_VD_FkYrF8/m/XDzix9lbAwAJ adding an example to show how to use 'scroll-target-group' property to highlight the currently visible chapter within a table of contents.
1 parent fc557ad commit eb4e1f7

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

css-overflow-5/Overview.bs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,42 @@ The 'scroll target group' property</h4>
250250

251251
</dl>
252252

253+
<div class='example'>
254+
The following snippet demonstrates how to automatically highlight the currently visible chapter within a table of contents
255+
<pre><code highlight="html">
256+
&lt;!DOCTYPE HTML&gt;
257+
&lt;title&gt;scroll-target-group example with a table of contents&lt;/title&gt;
258+
&lt;style&gt;
259+
ol {
260+
background-color: gray;
261+
right: 10px;
262+
top: 10px;
263+
position: fixed;
264+
/* Triggers the browser's algorithm for calculating :target-current. */
265+
scroll-target-group: auto;
266+
}
267+
268+
a:target-current {
269+
color: red;
270+
}
271+
272+
.chapter {
273+
background: lightgray;
274+
height: 60vh;
275+
margin: 10px;
276+
}
277+
&lt;/style&gt;
278+
&lt;ol&gt;
279+
&lt;li&gt;&lt;a href="#intro"&gt;Introduction&lt;/a&gt;&lt;/li&gt;
280+
&lt;li&gt;&lt;a href="#ch1"&gt;Chapter 1&lt;/a&gt;&lt;/li&gt;
281+
&lt;li&gt;&lt;a href="#ch2"&gt;Chapter 2&lt;/a&gt;&lt;/li&gt;
282+
&lt;/ol&gt;
283+
&lt;div id="intro" class="chapter"&gt;Introduction content&lt;/div&gt;
284+
&lt;div id="ch1" class="chapter"&gt;Chapter 1 content&lt;/div&gt;
285+
&lt;div id="ch2" class="chapter"&gt;Chapter 2 content&lt;/div&gt;
286+
</code></pre>
287+
</div>
288+
253289
<h4 id="scroll-marker-group-property">
254290
The 'scroll-marker-group' property</h4>
255291

0 commit comments

Comments
 (0)