Skip to content

Instantly share code, notes, and snippets.

@LiamChapman
Created February 16, 2018 14:36
Show Gist options
  • Select an option

  • Save LiamChapman/dfe9af6dc66174153b00bf75df55c7c0 to your computer and use it in GitHub Desktop.

Select an option

Save LiamChapman/dfe9af6dc66174153b00bf75df55c7c0 to your computer and use it in GitHub Desktop.
CSS for changing dimensions depending on the amount of elements in HTML
/* one item */
li:first-child:nth-last-child(1) {
width: 100%
}
/* two items */
li:first-child:nth-last-child(2),
li:first-child:nth-last-child(2) ~ li {
width: 50%;
}
/* three items */
li:first-child:nth-last-child(3),
li:first-child:nth-last-child(3) ~ li {
width: 33%;
}
/* four items */
li:first-child:nth-last-child(4),
li:first-child:nth-last-child(4) ~ li {
width: 25%;
}
/* and so on... */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment