Skip to content

Instantly share code, notes, and snippets.

@tortillaj
Created May 1, 2015 13:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tortillaj/d5a5887fbe25f49cad23 to your computer and use it in GitHub Desktop.
Save tortillaj/d5a5887fbe25f49cad23 to your computer and use it in GitHub Desktop.
Using the ampersand operator in Sass
<div class="container">
<h1>Nesting with the Ampersand Operator</h1>
<a href="#">It's common to use & on link styles.</a>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus ultrices, justo vel vulputate viverra, tortor nulla porta sem</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus ultrices, justo vel vulputate viverra, tortor nulla porta sem</p>
<p class="container__note">Here is a different kind of ampersand usage.</p>
</div>
// ----
// Sass (v3.4.13)
// Compass (v1.0.3)
// ----
$off-black: #4d4d4d;
.container {
a {
text-decoration: underline;
&:hover {
color: yellow;
background-color: $off-black;
text-decoration: none;
}
}
p {
&:first-of-type {
color: orange;
}
}
&__note {
background-color: gray;
padding: 5px;
color: white;
}
}
.container a {
text-decoration: underline;
}
.container a:hover {
color: yellow;
background-color: #4d4d4d;
text-decoration: none;
}
.container p:first-of-type {
color: orange;
}
.container__note {
background-color: gray;
padding: 5px;
color: white;
}
<div class="container">
<h1>Nesting with the Ampersand Operator</h1>
<a href="#">It's common to use & on link styles.</a>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus ultrices, justo vel vulputate viverra, tortor nulla porta sem</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus ultrices, justo vel vulputate viverra, tortor nulla porta sem</p>
<p class="container__note">Here is a different kind of ampersand usage.</p>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment