Skip to content

Instantly share code, notes, and snippets.

@finteractive
Last active January 3, 2016 20:19
Show Gist options
  • Save finteractive/8513957 to your computer and use it in GitHub Desktop.
Save finteractive/8513957 to your computer and use it in GitHub Desktop.
3. Introducing @extend
<html>
<body>
<div class="message-box">Hey Something happened</div>
<div class="message-box--success">Yay something worked!</div>
<div class="message-box--error">Warning Something is bad here <a href="#">Details</a></div>
<footer>&copy; 2014 - Someone <a href="#">legal link</a></a> </footer>
</body>
</html>
// ----
// Sass (v3.3.14)
// Compass (v1.0.1)
// ----
// More Variables - Introducing extends
// To remove duplication
// Color Variables
$grey-light: #444;
$grey-dark: #ddd;
$red: #ffaaaa;
$red-dark: darken($red, 50); // Added new red to variables
$red-extradark: darken($red, 80);
$green: #aaffaa;
// Layout Variables
$margins: 2em;
$padding: 1em;
.message-box {
background-color: $grey-dark;
border: 1px solid $grey-light;
margin: $margins;
padding: $padding;
text-align: center;
}
//// BEFORE
.message-box--success {
background-color: $green;
border: 1px solid $grey-light;
margin: $margins;
padding: $padding;
text-align: center;
}
.message-box--error {
background-color: $red;
border: 1px solid $grey-light;
margin: $margins;
padding: $padding;
text-align: center;
a {
color: $red-dark;
&:hover, &:active, &:focus {
color: $red-extradark;
}
}
}
//// AFTER
// .message-box--success {
// @extend .message-box;
// background-color: $green;
// }
// .message-box--error {
// @extend .message-box;
// background-color: $red;
// a {
// color: $red-dark;
// &:hover, &:active, &:focus {
// color: $red-extradark;
// }
// }
// }
.message-box {
background-color: #dddddd;
border: 1px solid #444444;
margin: 2em;
padding: 1em;
text-align: center;
}
.message-box--success {
background-color: #aaffaa;
border: 1px solid #444444;
margin: 2em;
padding: 1em;
text-align: center;
}
.message-box--error {
background-color: #ffaaaa;
border: 1px solid #444444;
margin: 2em;
padding: 1em;
text-align: center;
}
.message-box--error a {
color: #aa0000;
}
.message-box--error a:hover, .message-box--error a:active, .message-box--error a:focus {
color: #110000;
}
<html>
<body>
<div class="message-box">Hey Something happened</div>
<div class="message-box--success">Yay something worked!</div>
<div class="message-box--error">Warning Something is bad here <a href="#">Details</a></div>
<footer>&copy; 2014 - Someone <a href="#">legal link</a></a> </footer>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment