【发布时间】:2019-02-02 13:32:44
【问题描述】:
假设我有一个看起来像这样的 css 文件:
/* Base styles */
.content {
background-color: var(--background);
color: var(--text);
font-family: "Helvetica Neue", Helvetica, sans-serif;
font-size: 16px;
line-height: 1.5;
text-rendering: optimizeLegibility;
}
@media (min-width: 500px) {
.content {
font-size: 22px;
}
}
/* Headers */
h2 {
font-family: "Helvetica Neue", Helvetica, sans-serif;
font-size: 24px;
font-weight: 700;
}
/* Classes */
.small-caps {
font-feature-settings: "tnum";
letter-spacing: 0.05em;
}
使用 PostCSS,您可以像这样使用另一个类的属性:
.another-class {
composes: content from "other-file.css";
}
... 将被编译为:
.another-class {
background-color: var(--background);
color: var(--text);
font-family: "Helvetica Neue", Helvetica, sans-serif;
font-size: 16px;
line-height: 1.5;
text-rendering: optimizeLegibility;
}
是否可以让一个类从给定目标继承 所有 样式,以便您可以编写类似(伪代码)的内容:
.another-class {
composes: * from "other-file.css";
}
……渲染出来的效果是这样的?
/* Base styles */
.another-class .content {
background-color: var(--background);
color: var(--text);
font-family: "Helvetica Neue", Helvetica, sans-serif;
font-size: 16px;
line-height: 1.5;
text-rendering: optimizeLegibility;
}
@media (min-width: 500px) {
.another-class .content {
font-size: 22px;
}
}
/* Headers */
.another-class h2 {
font-family: "Helvetica Neue", Helvetica, sans-serif;
font-size: 24px;
font-weight: 700;
}
/* Classes */
.another-class .small-caps {
font-feature-settings: "tnum";
letter-spacing: 0.05em;
}
【问题讨论】:
-
我不经常使用捆绑程序或插件,但您在谈论这样的事情吗? stackoverflow.com/questions/11787330/…
标签: css webpack postcss css-modules