Skip to content

Instantly share code, notes, and snippets.

@chriseppstein
Created October 1, 2011 18:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save chriseppstein/1256490 to your computer and use it in GitHub Desktop.
Save chriseppstein/1256490 to your computer and use it in GitHub Desktop.
Cool things you may not know you could do with the & in sass
.tab {
.generatedcontent & {
&:before, &:after {
background-color: red;
}
.before, .after {
display: none;
}
}
}
/* ============== Compiles To ============== */
.generatedcontent .tab:before, .generatedcontent .tab:after {
background-color: red;
}
.generatedcontent .tab .before, .generatedcontent .tab .after {
display: none;
}
/* You can use the & multiple times in a single rule */
.context {
& .foo, &.foo, .foo & {
color: red;
}
}
/* ============== Compiles To ============== */
.context .foo, .context.foo, .foo .context {
color: red;
}
/* This isn't a & feature, but it is awesome. */
a, button, span.button {
> {
img, span.icon {
width: 12px;
height: 12px;
}
}
}
/* ============== Compiles To ============== */
a > img,
a > span.icon,
button > img,
button > span.icon,
span.button > img,
span.button > span.icon {
width: 12px;
height: 12px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment