字符串函數-quote()函數

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 “?);")

results matching ""

    No results matching ""