我怎么能这么做?
// style.scss
$primary-color: #dc4545;
div{
background : $primary-color;
}尝试这样做:
div{
background : var(--primary-color)
}这有可能吗?
发布于 2019-02-04 18:00:12
可以在:root上定义全局变量。
:root {
--primary-color: #dc4545;
}
div {
background: var(--primary-color);
}编辑:还是你试图混合和匹配?
$primary-color: #dc4545;
:root {
--primary-color: #{$primary-color};
}
div {
background: var(--primary-color);
}发布于 2019-02-04 18:07:16
首先,root和html选择器基本相同,但是:root具有比html选择器更高的特异性。
html {
}
/*****exactly :root and html selector are same but with higher specifity(:root)*****/
:root {
--color-primary-light: #FF3366;
--color-primary-dark: #BA265D;
--bakcground-color: #fff;
--default-font-size: 16px;
--color: blue;
}
/****************How to implement***************/
.root-selector {
background-color: var(--background-color);
font-size: var(--default-font-size);
color: var(--color);
}<div class="root-selector">
Thank you buddy
</div>
https://stackoverflow.com/questions/54521695
复制相似问题