Created
December 12, 2011 01:49
-
-
Save ry5n/1464180 to your computer and use it in GitHub Desktop.
Using Sass lists for DRY-er code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Shared colors for buttons and alerts | |
// | |
// Use Sass lists to avoid writing out repeating patterns of Sass code. | |
// | |
// For example, the following avoids having to write out a selector and | |
// set of style rules for each alert type, when only class and | |
// variable names are different. | |
// | |
// Follows (and many thanks to) Nathan Weizenbaum (@nex3)’s comment at: | |
// http://groups.google.com/group/sass-lang/msg/987926ad9fe5ad43? | |
// | |
// @note $info-color, $success-color, etc. are assumed to be assigned elsewhere. | |
// | |
// @note The background-image and linear-gradient functions are part of the | |
// Compass framework http://compass-style.org | |
.button, | |
.alert-message { | |
@each $alert-type in ( | |
info $info-color, | |
success $success-color, | |
warning $warning-color, | |
error $error-color, | |
danger $danger-color | |
) { | |
&.#{nth($alert-type, 1)} { | |
color: white; | |
background-color: nth($alert-type, 2); | |
@include background-image( | |
linear-gradient( rgba(black, 0), rgba(black, .05) ) | |
); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The equivalent, repetitious Scss without using list functions would be: