Skip to content

Instantly share code, notes, and snippets.

@finteractive
Created January 20, 2014 02:03
Show Gist options
  • Save finteractive/8513738 to your computer and use it in GitHub Desktop.
Save finteractive/8513738 to your computer and use it in GitHub Desktop.
2. Selector nesting and magic "&" selector, native SASS function
<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.0.rc.2)
// Compass (v1.0.0.alpha.17)
// ----
// Nesting Selectors, Sass functions
// Color Variables
$grey-light: #ddd;
$grey-dark: #444;
$red: #ffaaaa;
$green: #aaffaa;
// Layout Variables
$margins: 2em;
$padding: 1em;
.message-box {
background-color: $grey-light;
border: 1px solid $grey-dark;
margin: $margins;
padding: $padding;
text-align: center;
}
.message-box--success {
background-color: $green;
border: 1px solid $grey-dark;
margin: $margins;
padding: $padding;
text-align: center;
}
// I want the error link dark red, but not the footer link
// Also we need hover states
//// BEFORE
.message-box--error {
background-color: $red;
border: 1px solid $grey-dark;
margin: $margins;
padding: $padding;
text-align: center;
}
//// AFTER
// .message-box--error {
// background-color: $red;
// border: 1px solid $grey-dark;
// margin: $margins;
// padding: $padding;
// text-align: center;
// a {
// // Darken() is an example of a sass function
// // These should probably be a new variable $red-dark
// color: darken($red, 50);
// &:hover, &:active, &:focus {
// // Should be updated to a variable $red-extradark
// color: darken($red, 80);
// }
// }
// }
.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;
}
<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