一.字符串函数
(1).unquote()/quote()
h1{
&::before{
content:quote(Girl)
}
}
h1{
&::before{
content:quote('Girl')
}
}
//输出结果
h1::before{
content:quote("Girl")
}
h1{
&::before{
content:unquote('Girl')
}
}
//输出结果
h1::before{
content:quote(Girl)
}
h1{
&::before{
content:unquote("Gi'all");
}
}
h1::before{
content:'Gi' all
}
(2).to-upper-case/to-lower-case
h1{
&::before{
content:to-lower-case('AAA');
}
}
二.数字函数
(1).percentage
h1{
&::before{
content:percentage(2);
content:percentage(2px);//会报错,不可以传入单位
}
}
//编译结果
h1::before{
content:20%;
}
div{
width:round(10.2px);
}
//编译结果
div{
width:10px;
}
(3).ceil/floor
div{
width:ceil(1.4px);
}
//编译结果
div{
width:2px;
}
div{
width:floor(1.1px);
}
//编译结果
div{
width:1px;
}
div{
width:abs(-10px);
}
//编译结果
div{
width:10px;
}
(5).min/max
div{
width:min(1px,2px,3px);
}
//编译结果
div{
width:3px;
}
(6).random
div{
width:random();
}
//编译结果
div{
width:0.5994026302;
}
三.列表函数
(1).length
sass -i 开启命令
length<10px 20px 30px>
3
(2).nth
nth<10px 20px 30px,1>
(3).join
join<10px 20px, 30px 40px>
<10px 20px, 30px 40px>
join<<10px 20px, 30px 40px>,<50px 60px>>
(4).append
append((10px,20px),30px)
(10px,20px,30px)
(5).zip
zip(1px 2px 3px solid dashed dotted, green blue red)
((1px "solid" green),.....)
(6).index函数
index(1px 2px 3px, 1px) 1
四.判断函数
(1).typeof
type-pf(100) "number"
type-pf(100px) "number"
type-pf(qwe) "string"
type-pf("qwe") "string"
type-pf(true) "bool"
type-pf(#fff) "color"
(2).unit
unit(100px)
"px"
unit(100px/5em)
"px/em"
(3).unitless
unitless(100)
true
unitless(100px)
false
(4).comparable
comparable(1px,2px) true
comparable(1px,2em) false
五.三元条件函数
(1).三元条件函数
if(true,1px ,2px ) 1px
if(false,1px ,2px ) 2px
六.map数据地图
(1).map-get
$color:(default:blue,primary:red);
.box{
background-color:map-get($color,default)
}
$color:(
default:(bgcolor:blue,primary:red),
default1:(bgcolor:blue,primary:red)
);
.box{
background-color:map-get(map-get($color,default),"bgcolor")
}
(2).map-has-key
$theme-color:(
bgcolor:#fff,
text-color:#999
)
@if map-has-key($theme-color,bgcolor){
.box{
}
}
$theme-color:(
bgcolor:#fff,
text-color:#999
)
@if map-has-key($theme-color,bgcolor){
.box{
}
}@else{
@warn "这hi错误"
}
(3).map-keys
$theme-color:(
bgcolor:#fff,
text-color:#999
)
$list: map-keys($theme-color);
@each $name in $list{
.btn-#{$name}{
color:colors($name)
}
}
//编译结果
.btn-bgcolor{
color:#fff;
}
.btn-text-color{
color:#999;
}
(4).map-merge map合并
$theme-color:(
bgcolor:#fff,
text-color:#999
)
$typo:(
font-size:20px
)
$newmap:map-merge($theme-color,$typo)
(5).map-remove
$theme-color:(
bgcolor:#fff,
text-color:#999
)
$typo:(
font-size:20px
)
$newmap:map-remove($theme-color,bgcolor)
(6).kewords
@mixin map($args...){
@debug keywords($args)
}
@include map(
$bgcolor:red,
$font-size:14px,
$line-height:10px
)