我有点迷迷糊糊了。
我正在为Fontello编写mixin,但它使用\ sign将代码转换为图标。
如何将这个符号从SASS写到CSS?
示例:
我在地图上有图标:
$fontello-icon: (
facebook-rect: \e800,
facebook: \e801
);
然后用这个语句来写下来:
&:after
content: '#{map-get($fontello-icon, facebook)}'
但是css看起来像:
h1:after {
content: "\\e801";
而不是这样:
h1:after {
content: "\e801";
有人能帮我解决这个问题吗?
发布于 2016-06-02 08:37:38
为了添加到@Mark并提供一些上下文,在您的编译器中尝试下面的代码:
$a: \e801;
$b: '\e801';
@debug $a;
@debug '#{$a}';
@debug $b;
@debug '#{$b}';
记录的输出将是:
/style.scss:3 DEBUG: \e801 // <- Terminal has displayed the escaped `\\` as `\` (as appropriate for a program)
/style.scss:4 DEBUG: \e801 // <- Same as above
/style.scss:5 DEBUG: (A unicode character that I could not copy in)
/style.scss:6 DEBUG: (A unicode character that I could not copy in)
原因是SASS --或者任何一种编程语言--(如果我没记错的话,苹果的快速语言除外--他们可以在任何地方使用unicode )--不支持其他任何地方的unicode字符,而是支持字符串(即使这样,它也只支持表示,而不支持实际的字符)。因此,当您声明您的unicode字符串而没有使其为字符串时,就会假设它只是它们自己的切划机,就像单词sheep
只是[s,h,e,e,p]
,而\e801
只是[\,e,8,0,1]
--您想要的输出是[\e801]
。因此,将unicode存储在字符串中是一个普遍的想法。
发布于 2016-06-02 00:48:49
试一试
$fontello-icon: (
facebook-rect: '\e800',
facebook: '\e801'
);
&:after {
content: map-get($fontello-icon, #{facebook});
}
发布于 2016-06-02 08:58:58
好的。我用这个解决了这个问题..。
我搜索并找到了这篇文章:https://github.com/FortAwesome/Font-Awesome/pull/6728,其中有人用FontAwsome解决了同样的问题。
SassMeister这里:http://www.sassmeister.com/gist/3bfad69a4ca6e34909cf
结果是功能性的。
这里的整个代码:
斜杠功能:
@function PrepSlash($value) {
@return unquote('"\\#{$value}"');
}
代码地图:
$fontello-icon: (
facebook-rect: "e800",
facebook: "e801"
);
Sass代码:
&:after
content: PrepSlash(map-get($fontello-icon, facebook))
https://stackoverflow.com/questions/37574581
复制相似问题