Skip to content

Instantly share code, notes, and snippets.

@geoffreycrofte
Last active August 8, 2018 08:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geoffreycrofte/508332453c6a3538ae36 to your computer and use it in GitHub Desktop.
Save geoffreycrofte/508332453c6a3538ae36 to your computer and use it in GitHub Desktop.
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