We have a basic zebra stripe template that is included in our .less file for .list-striped.
We even work on a nested list, otherwise it changes the selectors, otherwise you will get an element of the parent list, and the first element of the list is a child with the same styles instead of opposites.
It works great. But we want to have N-level depth, so we don’t just want to embed styles into something higher than we think when the user ever nests, we hoped that something that could remove it and make it work for N-level instead of two-level lists?
I think I need magic nth-child(even)/nth-child(odd)for nested .list-item?
html basically
<div class="list-striped">
<div class="list-item">
<a class="title">List title</a>
<div class="list-striped">
<div class="list-item">
<a class="title">List title</a>
</div>
</div>
</div>
<div class="list-item">
<a class="title">List title</a>
<div class="list-striped">
<div class="list-item">
<a class="title">List title</a>
</div>
</div>
</div>
</div>
And 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;
}
}
}