Bra*_*ham 11 css webpack postcss css-modules
假设我有一个看起来像这样的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;
}
Run Code Online (Sandbox Code Playgroud)
使用PostCSS,您可以使用另一个类的属性,如下所示:
.another-class {
composes: content from "other-file.css";
}
Run Code Online (Sandbox Code Playgroud)
......将编译为:
.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;
}
Run Code Online (Sandbox Code Playgroud)
是否可以让一个类继承给定目标的所有样式,这样你就可以编写类似(伪代码)的东西:
.another-class {
composes: * from "other-file.css";
}
Run Code Online (Sandbox Code Playgroud)
......在渲染时它会像这样出现?
/* 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;
}
Run Code Online (Sandbox Code Playgroud)
使用 Sass (Scss) 可以实现这一点。
例子:
测试1.scss
.elem {
background: red;
@import 'test2';
}
Run Code Online (Sandbox Code Playgroud)
测试2.scss
.inner {
background: blue;
}
.outer {
background: green;
}
@media (max-width: 500px){
.something {
color: black;
}
}
Run Code Online (Sandbox Code Playgroud)
输出:
.elem {
background: red; }
.elem .inner {
background: blue; }
.elem .outer {
background: green; }
@media (max-width: 500px) {
.elem .something {
color: black; } }
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
194 次 |
| 最近记录: |