Skip to content

Instantly share code, notes, and snippets.

@rickharris
Forked from ry5n/dry-with-sass-lists
Created December 12, 2011 17:53
Show Gist options
  • Save rickharris/1468336 to your computer and use it in GitHub Desktop.
Save rickharris/1468336 to your computer and use it in GitHub Desktop.
Using Sass lists for DRY-er code
// 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