【问题标题】:Use CSS variables in Stylus iterations在 Stylus 迭代中使用 CSS 变量
【发布时间】:2019-04-05 12:44:53
【问题描述】:

https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_variables

例如,在像手写笔这样的 CSS 预处理器中:

// want to use this css variable
:root {
  --i-menu-count: 5
}

$item-count = 5
for $i in (1..$item-count) {
  .menu:nth-child({$i}) .menu-title {
    transform: rotate(-180deg / ($item-count - 1) * ($i - 1))
  }
}

是否可以在迭代中使用 CSS 变量 --i-menu-count 替换 $item-count

【问题讨论】:

    标签: css stylus css-variables


    【解决方案1】:

    我不确定,但- 是运算符,如果您的 var 名称以 -- 开头,则手写笔解析器会抛出错误

    我建议你在手写笔中声明你的计数

    喜欢

    item-count = 5
    
    for i in (1..item-count)
        .menu:nth-child({i}) .menu-title {
           transform: rotate(-180deg / (item-count - 1) * (i - 1))
        }
    

    【讨论】:

    • 我的意思是要把stylus的变量改成css变量,可以吗!?
    • 不,你不能,因为你不能用操作符命名你的手写笔变量,--var-name 包含“-”并且是操作符所以你不能
    猜你喜欢
    • 2012-10-15
    • 2015-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-15
    • 1970-01-01
    • 1970-01-01
    • 2014-01-07
    相关资源
    最近更新 更多