Skip to content

Instantly share code, notes, and snippets.

@jameswilson
Created August 1, 2014 22:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jameswilson/25fac6d66252f4cfba9c to your computer and use it in GitHub Desktop.
Save jameswilson/25fac6d66252f4cfba9c to your computer and use it in GitHub Desktop.
Columns based on number of siblings
/**
* Technique from http://lea.verou.me/2011/01/styling-children-based-on-their-number-with-css3/
*/
/* 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.3333%;
}
/* four items */
li:first-child:nth-last-child(4),
li:first-child:nth-last-child(4) ~ li {
width: 25%;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment