Sass - 检查变量具有哪种值 [英] Sass - Check which kind of value a variable has

查看:33
本文介绍了Sass - 检查变量具有哪种值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个变量:

$var: 5px;

但在代码中的某处,它的值已更改为可能的颜色数字emrm 等.

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?

@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 文档:

From the Sass documentation:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆