查找字符串是否在 sass 中的字符串中

Finding if a string is in string in sass

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

我如何在 mixin 中执行此操作?

 @mixin hello($mystring) {
 }

您可以使用 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;
}