Skip to content

Instantly share code, notes, and snippets.

@byrichardpowell
Created August 25, 2012 16:58
Show Gist options
  • Save byrichardpowell/3467893 to your computer and use it in GitHub Desktop.
Save byrichardpowell/3467893 to your computer and use it in GitHub Desktop.
Selectors should be 3 or less levels
/* BAD: The following selectors should be avoided if possible */
.one .two .three .four { /* styles */ }
.one ul li a { /* styles */ }
.one ul a:hover { /* styles */ }
.one ul li:first-child { /* styles */ }
/* BAD: Pre-processed nested selectors */
.one {
.two .three.four { /* styles */ }
ul li a { /* styles */ }
}
/* GOOD: No more than 3 levels deep */
.one .four { /* styles */ }
.one li a { /* styles */ }
.one a:hover { /* styles */ }
.one li:first-child { /* styles */ }
.one a:hover { /* styles */ }
/* ACCEPTIBLE: Discretion is advised */
/* This is 4 levels, but the extra specificity may be preferable */
.one li a:hover { /* styles */ }
.one li a.active { /* styles */ }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment