Skip to content

Instantly share code, notes, and snippets.

@jnowland
Last active August 29, 2015 14:06
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 jnowland/ca4441278418ea726dd8 to your computer and use it in GitHub Desktop.
Save jnowland/ca4441278418ea726dd8 to your computer and use it in GitHub Desktop.
Extends can be very bad.
/*
Using silent class
*/
.Button, .Random {
background: red;
}
div .Button {
color: red;
}
/* VS */
/*
Using a non silent class
*/
.Button2, .Random2 {
background: blue;
}
div .Button2, div .Random2 {
color: red;
}
/* Note that the css output on the last class is doubled.*/
/*
Alternate solution - use an attribute selector when you nest to stop the extend.
*/
.Button3, .Random3 {
background: yellow;
}
div [class*="Button3"] {
color: orange;
}
// ----
// Sass (v3.4.4)
// Compass (v1.0.1)
// ----
/*
Using silent class
*/
%background {
background:red;
}
.Button {
@extend %background;
}
.Random {
@extend %background;
}
div {
.Button {
color:red;
}
}
/* VS */
/*
Using a non silent class
*/
.Button2 {
background:blue;
}
.Random2 {
@extend .Button2;
}
div {
.Button2 {
color:red;
}
}
/* Note that the css output on the last class is doubled.*/
/*
Alternate solution - use an attribute selector when you nest to stop the extend.
*/
.Button3 {
background:yellow;
}
.Random3 {
@extend .Button3;
}
div {
[class*="Button3"] {
color:orange;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment