Sass - 检查变量具有哪种值 [英] Sass - Check which kind of value a variable has
本文介绍了Sass - 检查变量具有哪种值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有一个变量:
$var: 5px;
但在代码的某个地方,其价值已经变为可能的颜色,数字, em , rm 等。
but somewhere in code its value have changed in to possible color, number, em, rm etc.
是否有任何功能可以检测哪种类型它有价值吗?
Is there any function to detect which type of value it has?
ie
@if is-color($var) { //do something }
我知道sass中没有is-color函数但还有其他方法可以做到这一点或功能吗?
I know there is no is-color function in sass but are there other methods to do this or function?
推荐答案
来自Sass文档:
type_of($ value)
type_of($value)
返回值的类型。
示例:
type-of(100px) => number
type-of(asdf) => string
type-of("asdf") => string
type-of(true) => bool
type-of(#fff) => color
type-of(blue) => color
http://sass-lang.com/documentation/Sass/Script/Functions.html#type_of-instance_method
(注意 -
和 _
在Sass函数中是可互换的。)
(note that -
and _
is interchangeable in Sass functions).
这篇关于Sass - 检查变量具有哪种值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文