我正在尝试在 CSS/scss 中构建我自己的小型可扩展网格。到目前为止,我发现了这个决定:
:root {
--page-width: 1170px;
--gutter: 15px;
--columns: 12;
}
.wrapper {
max-width: var(--page-width);
margin-right: auto;
margin-left: auto;
padding-left: var(--gutter);
padding-right: var(--gutter);
}
.row {
margin-left: calc(-1 * var(--gutter));
margin-right: calc(-1 * var(--gutter));
}
.col {
display: block;
margin-left: var(--gutter);
margin-right: var(--gutter);
}
Run Code Online (Sandbox Code Playgroud)
然后我尝试使用 scss 来缩短列类描述(同时允许我在整个代码的一个地方更改列数 - 在 CSS Variable 中--columns)像这样
@for $n from 1 through var(--columns) {
.col-#{$n} {width: calc( #{$n} / var(--columns) - var(--gutter) * 2 ); }
}
Run Code Online (Sandbox Code Playgroud)
但它没有用。有趣的细节是,当我将@for语句从@for $n …
我正在尝试使用CSS变量进行一些实验,我无法使用它或找到任何有关它的文档.有谁知道在CSS3选择器中是否可以使用CSS var?
我做了以下示例来解释我正在尝试做什么.此示例仅适用于Chrome.
:root {
-webkit-var-count: 5; /* define my var! */
}
li {
width:100px;
height:100px;
background-color:blue;
display:inline-block;
list-style:none;
}
ul li:nth-child(4) {
background-color:red;
}
ul li:nth-child(-webkit-var(count)) { /* I can't get this working, is it even supported? I'm trying to target the 5th element with my var. */
background-color:black;
}
Run Code Online (Sandbox Code Playgroud)
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
Run Code Online (Sandbox Code Playgroud)