Created
December 11, 2013 23:57
-
-
Save indieisaconcept/7920840 to your computer and use it in GitHub Desktop.
Example of the wrong way of using variables with lists to display accent 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
<div class="news"> | |
<div class="module-header">news</div> | |
</div> | |
<div class="sport"> | |
<div class="module-header">sport</div> | |
</div> | |
<div class="business"> | |
<div class="module-header">business</div> | |
</div> |
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
// ---- | |
// Sass (v3.3.0.rc.1) | |
// Compass (v0.13.alpha.10) | |
// ---- | |
// Pass this look up function two arrays of equal dimensions and a search value | |
// If nothing is found in the first pass of the properties the values | |
// will then be indexed | |
// | |
// $property: an array of property values | |
// $value: an array of values | |
// $search: the property (or value) to get a matching value | |
// | |
// returns: a matching value from the index | |
// | |
// eg: | |
// | |
// $myProperties: a, b, c; | |
// $myValues: 1, 2, 3; | |
// searchLookup($myProperties, $myValues, b) = 2 | |
// searchLookup($myProperties, $myValues, 3) = c | |
// | |
@function searchLookup($property, $value, $search) { | |
$n1: index($property, $search); | |
$n2: index($value, $search); | |
@if($n1) { | |
@return nth($value, $n1); | |
} @else { | |
@return nth($property, $n2); | |
} | |
} | |
// VERTICAL BRANDING | |
$vertical-news-accent-color: blue !default; | |
$vertical-sport-accent-color: green !default; | |
$vertical-business-accent-color: grey !default; // Grey | |
// Create a hacky little lookup | |
$verticals: news, | |
sport, | |
business; | |
$vertical-accent: $vertical-news-accent-color, | |
$vertical-sport-accent-color, | |
$vertical-business-accent-color; | |
@each $vertical in $verticals { | |
.#{$vertical} .module-header { | |
background: searchLookup($verticals, $vertical-accent, $vertical); | |
} | |
} |
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
.news .module-header { | |
background: blue; | |
} | |
.sport .module-header { | |
background: green; | |
} | |
.business .module-header { | |
background: grey; | |
} |
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
<div class="news"> | |
<div class="module-header">news</div> | |
</div> | |
<div class="sport"> | |
<div class="module-header">sport</div> | |
</div> | |
<div class="business"> | |
<div class="module-header">business</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment