Skip to content

Instantly share code, notes, and snippets.

@gorillawit
Last active January 2, 2016 13:19
Show Gist options
  • Save gorillawit/8309476 to your computer and use it in GitHub Desktop.
Save gorillawit/8309476 to your computer and use it in GitHub Desktop.
Advanced Sass usage of parent selector (&)
// ----
// 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;
}
}
}
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