We have a basic zebra striping pattern going in our .less file for .list-striped
.
We even have it working for a nested list, aka, it reverses the selectors, otherwise you end up with the parent list item, and the first list item of the child having the same styles instead of being opposites.
This is working fine, But, we are wanting to have N-level depths, so we don't really want to just keep nesting the styles to something above whatever we think a user would ever nest, we were hoping there was something that could tidy this up and make it work for N-level instead of just 2-level lists?
I am thinking I need some nth-child(even)/nth-child(odd)
magic on the nested .list-item
?
- C1
- C2
- C1
- C2
- C1
- C2
- C2
- C2
- C2
- C1
- C2
The html is basically
<div class="list-striped">
<div class="list-item">
<a class="title">List title</a>
<!-- Start N-Level Nesting -->
<div class="list-striped">
<div class="list-item">
<a class="title">List title</a>
<!-- We could duplicate the n-level nesting item here as
much as we want -->
</div>
</div>
<!-- End N-level Nesting -->
</div>
<div class="list-item">
<a class="title">List title</a>
<!-- Start N-Level Nesting -->
<div class="list-striped">
<div class="list-item">
<a class="title">List title</a>
<!-- We could duplicate the n-level nesting item here as
much as we want -->
</div>
</div>
<!-- End N-level Nesting -->
</div>
</div>
And the css
div {
.list-striped {
.list-item:nth-child(odd) {
a {
background-color: @tableBackgroundAccent;
}
.list-striped {
.list-item:nth-child(odd) a {
background-color: @white;
}
.list-item:nth-child(even) a {
background-color: @tableBackgroundAccent;
}
}
}
.list-item:nth-child(even) {
a {
background-color: @white;
}
.list-striped {
.list-item:nth-child(even) a {
background-color: @white;
}
.list-item:nth-child(odd) a {
background-color: @tableBackgroundAccent;
}
}
}
}
&.list-hover {
.list-item:hover a {
background-color: @tableBackgroundHover;
}
}
}