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.
The :nth-child() in CSS Selector is used to select only those elements that are the nth child, regardless of type, of its parent.
You can pass in a positive number as an argument to :nth-child() , which will select the one element whose index inside its parent matches the argument of :nth-child() . For example, li:nth-child(3) will select the list item with an index value 3; that is, it will select the third list item.
However, from the current medical evidence, most medical authorities do state that if multiple C-sections are planned, the expert recommendation is to adhere to the maximum number of three.”
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:
@for $i from 1 through 8 {
li:nth-child(#{$i}) {
padding-left: $i * 20px
}
}
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With