I am trying to set up a color scheme in SCSS where I can have the following HTML:
<div class="swatch" data-bg="green">...</div>
I have a SCSS mixin defined as such:
@function color($key: 'black') {
@return map-get($colors, $key);
}
So, if I pass it background-color: color('green')
, it will look at the $colors: ( ... )
map, see 'green': #009900,
and return background-color: #009900;
as the CSS.
The problem comes when I try to pass the data-bg
attribute value into the color()
SCSS mixin, like so:
.swatch[data-bg] {
background-color: color(attr(data-bg));
}
This doesn't work. I would expect it to parse the value as such:
color(attr(data-bg))
→ color('green')
→ #009900
However, SCSS won't even render that background-color
line in the CSS at all.
I have a Codepen where you can see what I'm trying to go for. It's the "Brown" color swatch here: https://codepen.io/rbrum/pen/axZLxw
Any help would be greatly appreciated.