【问题标题】:Finding if a string is in string in sass查找字符串是否在 sass 中的字符串中
【发布时间】:2015-03-18 05:57:34
【问题描述】:

我想要一个 if 语句来显示一个字符串是否在 sass 中的另一个字符串中。

我如何在 mixin 中做到这一点?

 @mixin hello($mystring) {
 }

【问题讨论】:

  • 不是。 Mixins 不是函数,但是有a predefined function:str-slice($string, $start-at, [$end-at])

标签: sass mixins


【解决方案1】:

您可以使用str-index 来实现此目的。

SCSS

@mixin hello($mystring) {
  @if (str-index("Hello World", $mystring)) {
    background-color: green;
  }
  @else {
    background-color: blue;
  }
}

.test {
  @include hello("World");
}

CSS 输出

.test {
  background-color: green;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-01-09
    • 1970-01-01
    • 2011-01-11
    • 2023-04-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多