Loading...
li:first-child:nth-last-child(4),
li:first-child:nth-last-child(4) ~ li {
width: 25%;
}li {
width: calc(100% / sibling-count());
}One rule adapts to any number of items instead of a selector chain for each possible count.
display: none are still counted.sibling-count() instead of :nth-last-child chains or a custom property set by JavaScript.calc(), like calc(100% / sibling-count()).Yes. It counts all element children of the parent, including the element it is used on.
No. It counts only element siblings, not text or comment nodes.