Skip to content

Instantly share code, notes, and snippets.

@tortillaj
Created May 1, 2015 13:37
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/a4b931c5f76ec3b8e04c to your computer and use it in GitHub Desktop.
Save tortillaj/a4b931c5f76ec3b8e04c to your computer and use it in GitHub Desktop.
The @extend directive in Sass
<p class="button">Button</p>
<p>Somtimes you don't have control over the CSS class. In that case, you can "extend" a previously made class.</p>
<p class="something-else">Read More</p>
<p>Try overriding a propery in the .something-else class after the @extend directive.</p>
// ----
// Sass (v3.4.13)
// Compass (v1.0.3)
// ----
$off-black: #4d4d4d;
.button {
padding: 5px 10px;
border: 1px solid $off-black;
background-color: white;
appearance: none;
display: inline-block;
transition: background-color 0.25s ease;
&:hover {
cursor: pointer;
background-color: #ccc;
}
}
.something-else {
@extend .button;
}
.button, .something-else {
padding: 5px 10px;
border: 1px solid #4d4d4d;
background-color: white;
appearance: none;
display: inline-block;
transition: background-color 0.25s ease;
}
.button:hover, .something-else:hover {
cursor: pointer;
background-color: #ccc;
}
<p class="button">Button</p>
<p>Somtimes you don't have control over the CSS class. In that case, you can "extend" a previously made class.</p>
<p class="something-else">Read More</p>
<p>Try overriding a propery in the .something-else class after the @extend directive.</p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment