CSS是一个声明式的语言,主要为标记语言服务。并不具备很强的逻辑能力等。随着CSS的不断变革,CSS中也有具备了函数和运算相关的能力。php
function-name('参数/符号')
复制代码
如:css
calc(100%-40px)
复制代码
attr() 函数返回选择元素的属性值。html
<span class="tooltip-toggle"
aria-label="Sample text for your tooltip!"
tabindex="0">
.tooltip-toggle::before { content: attr(aria-label); }
复制代码
calc()能够说是一个计算器,咱们能够在里面运行咱们的计算表达式。express
.element {
width: calc(expression);
}
复制代码
功能和url()函数相似,只是功能更为强大。能够指定回退图像,对具备方向的图像进行注释等。浏览器
.special { color: white;
background: image("dark.png", black); }
复制代码
相似于background-image经过url()加载失败时,采用background-color作为降级。bash
image(ltr "arrow.png")
image(rtl "arrow.png")
复制代码
补充:关于ltr和rtlapp
能够将网站中的某部分看成图片渲染(仅Firefox支持这个特性)函数
<div id="css-source">
<p>Lorem ipsum</p>
<img src="" alt="">
</div>
<div id="css-result"></div>
#css-result { background: element(#css-source);
background-size: 50% 50%; }
复制代码
示例网站
filter能够用来作各类滤镜(webkit支持,高版本)
element {
filter: none | <filter-function > [ <filter-function> ]*
}
复制代码
滤镜函数:模糊blur()、亮度brightness()、对比度contrast()、阴影drop-shadow()、灰度grayscale()、hue-rotate()、invert()、透明度opacity()、saturate()、sepia()
grayscale{-webkit-filter:grayscale(1);}
复制代码
转换函数指的是CSS的transform中用到的属性值。
该函数容许后代元素循环遍历一个值列表(浏览器仍不支持)
ul{list-style-type:disk;}
li > ul{list-style-type:toggle(disk,circle,square,box);}
复制代码
用来调用CSS中自定义属性
:root { --color: red }
.test { color: var(--color) }
复制代码
counter()、counters()、toggle()、var()和symbols()