我试图改变颜色的改变对比(添加更改对比类到身体)在scss中。
我的静态颜色是:
$原色-蓝色:#2 aace2;
$中蓝色:#2695d2;
$深蓝色:#124b62;
关于change对比度:
$原色-蓝色:#177 blue;
中蓝色:#1c6f9b;
$深蓝色:#124b62;
应该像在sass那样
if(change-contrast) {
// console.log (get High Constrast Colors)
}
else {
// console.log (Static Colors)
}我试着像下面这样做,但如果我喜欢下面,我必须增加每一节课。
@mixin branding {
@each $brand in $brand_clr {
&.#{nth($brand,1)} {
$primary-color-blue: #177eab;
@content;
}
}
}
test {
background: $primary-color-blue;
@include branding {
background: $primary-color-blue;
}
} 感谢你在这方面的帮助!
谢谢
发布于 2018-04-13 14:16:06
我认为解决方案遇到了一个结构良好的彩色地图。你需要按类型对颜色进行分组。静态的,对比的)。然后,使用一个混合,以避免重复你自己。
$colors:(
standard: (
primary-color-blue: #2aace2,
mid-blue-color:#2695d2,
dark-blue-color:#124b62
),
contrasted: (
primary-color-blue: #177eab,
mid-blue-color:#1c6f9b,
dark-blue-color:#124b62
)
);
@function get-color($key, $type: 'standard'){
@each $name, $color in map-get($colors, $type){
@if($key == $name){
@return $color
}
}
}
@mixin get-color($property,$color){
#{$property}: get-color($color);
@at-root body.contrasted & {
#{$property}: get-color($color, contrasted);
}
}
.className{
@include get-color(background-color, primary-color-blue)
}这将产生以下结果:
.className {
background-color: #2aace2;
}
body.contrasted .className {
background-color: #177eab;
}https://stackoverflow.com/questions/49809524
复制相似问题