quote() 函数刚好与 unquote() 函数功能相反,主要用来给字符串添加引号。如果字符串,自身带有引号会统一换成双引号 ""。如:
//SCSS .test1 { content: quote(‘Hello Sass!‘); } .test2 { content: quote("Hello Sass!"); } .test3 { content: quote(ImWebDesigner); } .test4 { content: quote(‘ ‘); }
编译出来的 css 代码:
//CSS .test1 { content: "Hello Sass!"; } .test2 { content: "Hello Sass!"; } .test3 { content: "ImWebDesigner"; } .test4 { content: ""; }
使用 quote() 函数只能给字符串增加双引号,而且字符串中间有单引号或者空格时,需要用单引号或双引号括起,否则编译的时候将会报错。
.test1 { content: quote(Hello Sass); }
这样使用,编译器马上会报错:
error style.scss (Line 13: $string: ("Hello""Sass") is not a string for `quote‘)
解决方案就是去掉空格,或者加上引号:
.test1 { content: quote(HelloSass); } .test1 { content: quote("Hello Sass"); }
同时 quote() 碰到特殊符号,比如: !、?、> 等,除中折号 - 和下划线_ 都需要使用双引号括起,否则编译器在进行编译的时候同样会报错:
error style.scss (Line 13: Invalid CSS after "...quote(HelloSass": expected ")", was "!);") error style.scss (Line 16: Invalid CSS after "...t: quote(Hello": expected ")", was “?);")