假设我有一个如下所示的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;
}发布于 2018-09-12 19:35:58
这是可以使用Sass (Scss)的。
示例:
test1.scss
.elem {
background: red;
@import 'test2';
}test2.scss
.inner {
background: blue;
}
.outer {
background: green;
}
@media (max-width: 500px){
.something {
color: black;
}
}输出:
.elem {
background: red; }
.elem .inner {
background: blue; }
.elem .outer {
background: green; }
@media (max-width: 500px) {
.elem .something {
color: black; } }发布于 2018-09-17 09:15:24
是的是可能的。您可以像使用css一样使用SASS来实现这一点。
.error {
border: 1px #f00;
background-color: #fdd;
}
.seriousError {
border-width: 3px;
}你可以把它当作
.error {
border: 1px #f00;
background-color: #fdd;
}
.seriousError {
@extend .error;
border-width: 3px;
}@extend指令通过告诉Sass一个选择器应该继承另一个选择器的样式来避免这些问题。
有关更多细节,请参考SASS文件。
https://stackoverflow.com/questions/52049011
复制相似问题