【发布时间】:2015-03-18 05:57:34
【问题描述】:
我想要一个 if 语句来显示一个字符串是否在 sass 中的另一个字符串中。
我如何在 mixin 中做到这一点?
@mixin hello($mystring) {
}
【问题讨论】:
-
不是。 Mixins 不是函数,但是有a predefined function:
str-slice($string, $start-at, [$end-at])
我想要一个 if 语句来显示一个字符串是否在 sass 中的另一个字符串中。
我如何在 mixin 中做到这一点?
@mixin hello($mystring) {
}
【问题讨论】:
str-slice($string, $start-at, [$end-at])
您可以使用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;
}
【讨论】: