Skip to content

Commit f7b261b

Browse files
committed
[selectors] Add an example of using :nth-child(even of foo) for zebra-striping.
--HG-- extra : rebase_source : e6fee4680ef0745fa86db2816ba57dc8ce68c67b
1 parent a80455b commit f7b261b

2 files changed

Lines changed: 328 additions & 243 deletions

File tree

selectors/Overview.bs

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ Abstract: Selectors Level 4 describes the selectors that already exist in [[!SEL
2121
At Risk: the column combinator
2222
At Risk: the '':drop()'' pseudo-class
2323
At Risk: the '':read-write'' pseudo-class
24-
Ignored Terms: DocumentFragment, math, h1, shadow tree, box tree, query(), element tree
25-
Link Defaults: html5 (element) a
24+
Ignored Terms: DocumentFragment, math, h1, shadow tree, box tree, query(), element tree, quirks mode
25+
Link Defaults: html5 (element) a, dom-core-ls (interface) document
2626
</pre>
2727
<style>
2828
.tprofile td, th { vertical-align: baseline; padding: 0 0.5em; }
@@ -2640,6 +2640,40 @@ Child-indexed Pseudo-classes</h3>
26402640
if they also have the ''.important'' class.
26412641
</div>
26422642

2643+
<div class="example">
2644+
Here's another example of using the selector argument,
2645+
to ensure that zebra-striping a table works correctly.
2646+
2647+
Normally, to zebra-stripe a table's rows,
2648+
an author would use CSS similar to the following:
2649+
2650+
<pre>
2651+
tr {
2652+
background: white; \
2653+
}
2654+
tr:nth-child(even) {
2655+
background: silver;
2656+
}
2657+
</pre>
2658+
2659+
However, if some of the rows are hidden and not displayed,
2660+
this can break up the pattern,
2661+
causing multiple adjacent rows to have the same background color.
2662+
Assuming that rows are hidden with the ''[hidden]'' attribute in HTML,
2663+
the following CSS would zebra-stripe the table rows robustly,
2664+
maintaining a proper alternating background
2665+
regardless of which rows are hidden:
2666+
2667+
<pre>
2668+
tr {
2669+
background: white;
2670+
}
2671+
tr:nth-child(even of :not([hidden])) {
2672+
background: silver;
2673+
}
2674+
</pre>
2675+
</div>
2676+
26432677
<h4 id="the-nth-last-child-pseudo">
26442678
'':nth-last-child()'' pseudo-class</h4>
26452679

0 commit comments

Comments
 (0)