Sass函数字符串函数_html/css_WEB-ITnose
Sass的函数简介
在 Sass 中除了可以定义变量,具有 @extend、%placeholder 和 mixins 等特性之外,还自备了一系列的函数功能。其主要包括:
● 字符串函数
● 数字函数
● 列表函数
● 颜色函数
● Introspection 函数
● 三元函数等
当然除了自备的函数功能之外,我们还可以根据自己的需求定义函数功能,常常称之为自定义函数。
字符串函数
字符串函数顾名思意是用来处理字符串的函数。Sass 的字符串函数主要包括两个函数:
unquote($string): 删除字符串中的引号;quote($string):给字符串添加引号。
1、unquote()函数
unquote() 函数主要是用来删除一个字符串中的引号,如果这个字符串没有带有引号,将返回原始的字符串。
1 //SCSS 2 .test1 { 3 content: unquote('Hello Sass!') ; 4 } 5 .test2 { 6 content: unquote("'Hello Sass!"); 7 } 8 .test3 { 9 content: unquote("I'm Web Designer");10 }11 .test4 {12 content: unquote("'Hello Sass!'");13 }14 .test5 {15 content: unquote('"Hello Sass!"');16 }17 .test6 {18 content: unquote(Hello Sass);19 }
编译后的 css 代码:
1 //CSS 2 .test1 { 3 content: Hello Sass!; 4 } 5 .test2 { 6 content: 'Hello Sass!; 7 } 8 .test3 { 9 content: I'm Web Designer; 10 }11 .test4 {12 content: 'Hello Sass!'; 13 }14 .test5 {15 content: "Hello Sass!"; 16 }17 .test6 {18 content: Hello Sass; 19 }
注意: unquote() 函数只能删除字符串最前和最后的引号(双引号或单引号),而无法删除字符串中间的引号。如果字符没有带引号,返回的将是字符串本身。
2、quote()函数
quote() 函数刚好与 unquote() 函数功能相反,主要用来给字符串添加引号。如果字符串,自身带有引号会统一换成双引号 ""。
如:
1 //SCSS 2 .test1 { 3 content: quote('Hello Sass!'); 4 } 5 .test2 { 6 content: quote("Hello Sass!"); 7 } 8 .test3 { 9 content: quote(ImWebDesigner);10 }11 .test4 {12 content: quote(' ');13 }
编译出来的 css 代码:
1 //CSS 2 .test1 { 3 content: "Hello Sass!"; 4 } 5 .test2 { 6 content: "Hello Sass!"; 7 } 8 .test3 { 9 content: "ImWebDesigner";10 }11 .test4 {12 content: "";13 }
使用 quote() 函数只能给字符串增加双引号,而且字符串中间有单引号或者空格时,需要用单引号或双引号括起,否则编译的时候将会报错。
1 .test1 {2 content: quote(<strong>Hello Sass</strong>);3 }4 //这样使用,编译器马上会报错:error style.scss (Line 13: $string: ("Hello""Sass") is not a string for `quote')
解决方案就是去掉空格,或者加上引号:
1 .test1 {2 content: quote(<strong>HelloSass</strong>);3 }4 .test1 {5 content: quote(<strong>"Hello Sass"</strong>);6 }
同时 quote() 碰到特殊符号,比如: !、?、> 等,除中折号 - 和 下划线_ 都需要使用双引号括起,否则编译器在进行编译的时候同样会报错。
字符串函数-To-upper-case()、To-lower-case()
1、To-upper-case()
To-upper-case() 函数将字符串小写字母转换成大写字母。如:
1 //SCSS2 .test {3 text: to-upper-case(aaaaa);4 text: to-upper-case(aA-aAAA-aaa);5 }
编译出来的 css 代码:
1 //CSS2 .test {3 text: AAAAA;4 text: AA-AAAA-AAA;5 }
2、To-lower-case()
To-lower-case() 函数与 To-upper-case() 刚好相反,将字符串转换成小写字母:
1 //SCSS2 .test {3 text: to-lower-case(AAAAA);4 text: to-lower-case(aA-aAAA-aaa);5 }
编译出来的 css 代码:
1 //CSS2 .test {3 text: AAAAA;4 text: AA-AAAA-AAA;5 }
◑

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The article discusses the HTML <progress> element, its purpose, styling, and differences from the <meter> element. The main focus is on using <progress> for task completion and <meter> for stati

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

The article discusses the HTML <datalist> element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

The article discusses the viewport meta tag, essential for responsive web design on mobile devices. It explains how proper use ensures optimal content scaling and user interaction, while misuse can lead to design and accessibility issues.

The article discusses the <iframe> tag's purpose in embedding external content into webpages, its common uses, security risks, and alternatives like object tags and APIs.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

The article discusses the HTML <meter> element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates <meter> from <progress> and ex

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.
