I'm currently working on setting up a color scheme in SCSS that allows me to use the following HTML structure:
<div class="swatch" data-bg="green">...</div>
In my SCSS file, I have defined a mixin like this:
@function color($key: 'black') {
@return map-get($colors, $key);
}
With this setup, if I pass background-color: color('green')
, it will look for 'green': #009900
in the $colors
map and return background-color: #009900;
as the CSS output.
However, when I try to pass the value of the data-bg
attribute into the color()
SCSS mixin, it doesn't seem to work as expected. Here's how I tried to implement it:
.swatch[data-bg] {
background-color: color(attr(data-bg));
}
This implementation fails to render the background-color
line in the CSS at all. Ideally, I would expect the parsing to flow like this:
color(attr(data-bg))
→ color('green')
→ #009900
If you'd like to see the problem I'm facing, check out the "Brown" color swatch on this Codepen: https://codepen.io/rbrum/pen/axZLxw
I would greatly appreciate any assistance with this issue.