Assuming we have a css list as such
<ul class="parent">
<li class="child"></li>
</ul>
with the child items being generated based from an iterator. How can you get the number of children within parent in either css or scss.
So I can dynamically modify css attributes like padding
based on the nth child.
Use nth child as explained in this article https://alistapart.com/article/quantity-queries-for-css
Use direct children selector
>
and add nth pattern for example:Neither CSS nor SASS will tell you how many items there are in a list. You'll need JS for that.
However, with SASS you can generate the CSS for as many children as you want automatically:
Change the number 8 to any number you think will have you covered (10? 100? 1000?).
More info: http://clubmate.fi/for-while-and-each-loops-in-sass/