相关疑难解决方法(0)

如何将 CSS 变量值分配给 scss 变量或表达式

我正在尝试在 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 sass css-variables

6
推荐指数
2
解决办法
4966
查看次数

是否可以在CSS3选择器中使用CSS变量?

我正在尝试使用CSS变量进行一些实验,我无法使用它或找到任何有关它的文档.有谁知道在CSS3选择器中是否可以使用CSS var?

我做了以下示例来解释我正在尝试做什么.此示例仅适用于Chrome.

的jsfiddle

http://jsfiddle.net/68Rrn/

CSS

: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)

HTML

<ul>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
</ul>
Run Code Online (Sandbox Code Playgroud)

html css css-selectors css3 css-variables

4
推荐指数
1
解决办法
613
查看次数

标签 统计

css ×2

css-variables ×2

css-selectors ×1

css3 ×1

html ×1

sass ×1