Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A way to apply styles depending on number of elements
li:only-of-type {
width: 100%;
}
/* if 2 <ul> childs */
li:nth-last-child(2):first-child,
li:nth-last-child(2):first-child ~ li {
width: 50%;
}
/* if 3 <ul> childs */
li:nth-last-child(3):first-child,
li:nth-last-child(3):first-child ~ li {
width: 33.333%;
}
/* etc. */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.