【发布时间】:2022-02-20 01:06:51
【问题描述】:
我有下一个 postcss 配置
module.exports = {
plugins: [
[
'postcss-preset-env',
{
browsers: 'last 2 versions, IE 11, not dead',
preserve: false,
features: {
'custom-media-queries': true,
'custom-properties': true,
'nesting-rules': true
},
importFrom: ['src/styles/variables.css']
}
]
]
}
还有这个带有 css 变量的文件
@custom-media --desktop screen and (min-width: 768px);
@custom-media --mobile screen and (max-width: 767px);
:root {
--montserrat: montserrat, sans-serif;
--sfProDisplay: sf pro display, sans-serif;
--helvetica: helvetica, sans-serif;
--blue: #315efb;
--middleBlue: #2c54e2;
--darkBlue: #274bc8;
--lightBlue: #e0ebff;
--green: #21a038;
--grey: #62687f;
--darkGray: #343b4c;
--blueGray: #8d96b2;
--cloudGray: #f3f4f7;
--cloudGray7: #afb6c9;
--darkCarbone: #1f2431;
--paleYellow: #fffde5;
--red: #ff564e;
}
在我通过 next build && next export 构建项目后,颜色显示不正确。例如,颜色:var(--blueGray),而不是颜色:#8d96b2。有人知道出了什么问题吗?
【问题讨论】:
-
您能否分享一个定义颜色属性的示例、它的用法、它的外观以及当前的外观?
-
所以 PostCSS 正在从自定义属性中删除
--? -
是的,我添加了照片。它看起来像照片,但应该是颜色:#8d96b2,而不是颜色:var(--blueGray)
-
那个输出是正确的。 CSS 颜色应该是
--blueGray。如果您将鼠标悬停在它上面,它应该会告诉您浏览器说该属性当前是什么。请记住,它们不像 SASS 变量,它们是运行时,而不是编译时。 -
但是如果我运行开发服务器,颜色是#8d96b2 并正确显示
标签: javascript reactjs next.js postcss