【问题标题】:figuring out sass mixins搞清楚 sass mixins
【发布时间】:2014-04-09 19:03:02
【问题描述】:

我是 sass 的新手,我试图让我的头脑围绕 mixins 并在 mixins 中使用 if/else 语句。我正在尝试写一些简单的东西,基本上说如果选择器的宽度设置大于 50%,它将是某种颜色,否则它将是不同的颜色。

这是我到目前为止的代码:

@mixin color-class($width) {
  @if "$width > 50%" {
    background-color: purple;

  } @else {
      background-color: orange; 
    }
}

.selector-two {
  @include color-class(40%);
}

.selector-three {
  @include color-class(80%);
}

无论我在这里输入什么值,css 都会将颜色输出为紫色,所以我肯定遗漏了一些东西,任何帮助将不胜感激。

【问题讨论】:

    标签: if-statement sass mixins


    【解决方案1】:

    尝试删除"

    @if $width > 50% {}
    

    您可以在这里快速试验一下:http://sassmeister.com/

    【讨论】:

    • 谢谢,成功了!这种语法每次都让我很开心......你提到 sassmeister 很有趣,我的导师是开发该语法的人之一。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-07
    • 1970-01-01
    • 1970-01-01
    • 2012-12-13
    • 2015-08-25
    相关资源
    最近更新 更多