Last active
May 10, 2017 09:10
-
-
Save nathos/1212291 to your computer and use it in GitHub Desktop.
Using lists like a hash in Sass
This file contains 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
@mixin category-colors($after: false) | |
@each $category in $categories | |
@if $after == true | |
.cat-#{nth($category, 1)}:after | |
background-color: nth($category, 2) | |
@else | |
.cat-#{nth($category, 1)} | |
background-color: nth($category, 2) |
This file contains 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
// Categories & Category Colors | |
// this is a comma-separated list of space-separated lists! | |
$categories: site teal, youth orange, poetry plum, fiction salmon, creativewriting steelblue | |
// The placeholder selector we'll be @extending -- placeholder selectors require Sass 3.2 | |
%category-colors | |
@include category-colors | |
.category-banners | |
li | |
// @extend the color classes into the list items | |
@extend %category-colors |
This file contains 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
/* Note that the placeholder class isn't output in the CSS */ | |
.category-banners li .cat-site { | |
background-color: teal; | |
} | |
.category-banners li .cat-youth { | |
background-color: orange; | |
} | |
.category-banners li .cat-poetry { | |
background-color: plum; | |
} | |
.category-banners li .cat-fiction { | |
background-color: salmon; | |
} | |
.category-banners li .cat-creativewriting { | |
background-color: steelblue; | |
} |
I could kiss you right now, man...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hmm, this looks pretty cool, and almost solves a problem i'm having, except my "hash" would have so many options in it it would get confusing. I need a true hash to keep things orderly.