Sass 3.4 删除字符串上的正斜杠 [英] Sass 3.4 Removing forward slash on a string
问题描述
是否有解决方法或任何其他方法可以使这项工作在 Sass 3.4 + 上运行?
is theres a workaround or any other ways to make this work on Sass 3.4 +
@mixin icon ($name, $code) {
.#{$name}::before {
content: str-slice("\x",1,1) + $code;}
}
@include icon('test', 4556);
代码应该输出
.test::before { content: "\4556";}
.test::before { content: "\4556"; }
但是在 3.4+ 上,\
斜杠被删除并输出为
But on 3.4+ the \
slash is getting removed and outputted as
.test::before { content: "x4556";}
.test::before { content: "x4556"; }
谢谢
推荐答案
您偶然发现了一个 当前有争议的转义字符问题在 Sass 中.目前看来,Sass 要么添加太多字符,要么最终将 unicode 字符放入输出 css 中.
You stumbled across a currently-debated issue with escape characters in Sass. It seems that, currently, Sass will either add too many characters, or winds up putting the unicode character into the output css.
@mixin icon ($name, $code) {
$withslash: "\"\\#{$code}\"";
.#{$name}:before {
content: unquote($withslash);
}
}
@include icon('test', '4556');
输出
.test:before {
content: "\4556";
}
http://sassmeister.com/gist/04f5be11c5a6b26b8ff9
显然,这种方法的缺点是它依赖于使用转义字符做一些奇怪的事情,并欺骗 Sass 取消对可能格式错误的字符串的引用.
Obviously the drawback to this approach is that it relies on doing weird things with an escape character and tricking Sass into unquoting a possibly malformed string.
这篇关于Sass 3.4 删除字符串上的正斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!