Sass is outputting #000 and #fff as black and white color values in my css file. For example:
$color: #000;
.box {
color: $color;
}
Outputs to:
.box {
color: black;
}
Shouldn't output the hex values?
How Sass treats colors varies depending on what version you're using. But there are a few common behaviors:
rgba(0, 0, 0, 100)
, Sass will convert it to either black
or #000
)#000000
will be output as #000
).Sass only converts colors when they are used as variables or if they are not in one of the 3 formats as described above:
$color-hex: #000000;
$color-keyword: black;
$color-rgb: rgb(0, 0, 0);
$color-hsl: hsl(0, 0, 0);
.box-hex {
color: $color-hex;
background: #000000;
}
.box-keyword {
color: $color-keyword;
background: black;
}
.box-rgb {
color: $color-rgb;
background: rgb(0, 0, 0);
}
.box-hsl {
color: $color-hsl;
background: hsl(0, 0, 0);
}
Output:
.box-hex {
color: black;
background: #000000;
}
.box-keyword {
color: black;
background: black;
}
.box-rgb {
color: black;
background: black;
}
.box-hsl {
color: black;
background: black;
}
The only change from 3.3 to 3.4 is that when using variables, Sass will preserve the format of your color... unless it is in something other than the keyword, hex, or rgba formats.
.box-hex {
color: #000000;
background: #000000;
}
If you absolutely must have a specific format, you can turn it into a string:
$color: #{'#F00'}; // or `unquote('#F00')`
.foo {
color: $color;
}
Output:
.foo {
color: #F00;
}
Just keep in mind that when you do this, your "color" will not work with color manipulation functions like lighten()
or darken()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With