Last active
January 2, 2016 13:19
-
-
Save gorillawit/8309476 to your computer and use it in GitHub Desktop.
Advanced Sass usage of parent selector (&)
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
// ---- | |
// Sass (v3.3.0.rc.1) | |
// Compass (v0.13.alpha.10) | |
// ---- | |
//improved ampersands | |
div{ | |
background: green; | |
& & { | |
color: blue; | |
} | |
& + & { | |
text-align: right; | |
} | |
} | |
//can use for more complex functions as well | |
.my-widget { | |
//my widget is normaly red | |
color: red; | |
@at-root { | |
//but with the below #{&}, div.my-widget will be green | |
div#{&} { | |
color:green; | |
} | |
} | |
} |
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
div { | |
background: green; | |
} | |
div div { | |
color: blue; | |
} | |
div + div { | |
text-align: right; | |
} | |
.my-widget { | |
color: red; | |
} | |
div.my-widget { | |
color: green; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment