I am looking for the simplest way to zebra stripe the rows on the following responsive flexbox table.
In other words, rows 2 and 4 in this example, but unlimited, I can't know how many rows there will be because this is for a reusable component in a CMS system.
The HTML cannot change but the number of rows and columns will change often. I am happy with setting a limit on columns but not rows.
Is there any way to do it in pure CSS?
.Rtable {
display: flex;
flex-wrap: wrap;
}
.Rtable-cell {
box-sizing: border-box;
flex: 33.33%;
margin: -1px 0 0 -1px;
padding: 5px 10px;
border: solid 1px slategrey;
}
h3 { margin: 0; }
@media all and (max-width: 500px) {
.Rtable {
display: block;
}
}
<div class="Rtable">
<div style="order:1;" class="Rtable-cell"><h3>Eddard Stark</h3></div>
<div style="order:2;" class="Rtable-cell">Has a sword named Ice</div>
<div style="order:3;" class="Rtable-cell">No direwolf</div>
<div style="order:4;" class="Rtable-cell">Male</div>
<div style="order:5;" class="Rtable-cell"><strong>Lord of Winterfell</strong></div>
<div style="order:1;" class="Rtable-cell"><h3>Jon Snow</h3></div>
<div style="order:2;" class="Rtable-cell">Has a sword named Longclaw</div>
<div style="order:3;" class="Rtable-cell">Direwolf: Ghost</div>
<div style="order:4;" class="Rtable-cell">Male</div>
<div style="order:5;" class="Rtable-cell"><strong>Knows nothing</strong></div>
<div style="order:1;" class="Rtable-cell"><h3>Arya Stark</h3></div>
<div style="order:2;" class="Rtable-cell">Has a sword named Needle</div>
<div style="order:3;" class="Rtable-cell">Direwolf: Nymeria</div>
<div style="order:4;" class="Rtable-cell">Female</div>
<div style="order:5;" class="Rtable-cell"><strong>No one</strong></div>
</div>
See Question&Answers more detail:os