Created
October 2, 2014 23:14
-
-
Save markbrown4/3c90bfd119544ddc90f1 to your computer and use it in GitHub Desktop.
css nested selectors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* It's common to want to make the selector nesting the same as the dom */ | |
#content { | |
.nav { | |
ul { | |
margin: 0; | |
padding: 0; | |
li { | |
float: left; | |
margin: 0; | |
padding: 0; | |
a { | |
float: left; | |
.icon { | |
font-size: 12px; | |
} | |
} | |
} | |
} | |
} | |
} | |
/* It's much better to keep the selectors to the minimum required by the structure/css */ | |
#content .nav { | |
ul { | |
margin: 0; | |
padding: 0; | |
} | |
li { | |
float: left; | |
margin: 0; | |
padding: 0; | |
} | |
a { | |
float: left; | |
} | |
.icon { | |
font-size: 12px; | |
} | |
} | |
/* It's the exact same as I'd write without sass, but without the duplicated context */ | |
#content .nav ul { | |
margin: 0; | |
padding: 0; | |
} | |
#content .nav li { | |
float: left; | |
margin: 0; | |
padding: 0; | |
} | |
#content .nav a { | |
float: left; | |
} | |
#content .nav .icon { | |
font-size: 12px; | |
} | |
/* Sass's nesting is great, if you keep nesting to a logical context you're golden */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment