是否有一个字符串函数可以删除SASS中字符串中的空格?
对于一个实例,我想使用一个变量(带空格的字符串)来指定资源镜像文件(名称不带空格)。
就像是:
$str-var: "The White Lion";
@mixin bg-img($name) {
background-image: url("#{$name}.jpg");
}
.image-cover {
@include bg-img(str-remove-whitespace($str-var));
}
预期结果:
.image-cover {
background-image: url("TheWhiteLion.jpg");
}
最佳答案
没有这样的内置函数,但是可以通过在字符串中搜索空格并将其切掉来实现。这样的事情应该起作用:
@function str-remove-whitespace($str) {
@while (str-index($str, ' ') != null) {
$index: str-index($str, ' ');
$str: "#{str-slice($str, 0, $index - 1)}#{str-slice($str, $index + 1)}";
}
@return $str;
}
您可以在SASS documentation中看到的可用功能列表。
关于sass - 如何删除SASS字符串中的空格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46805243/