gpt4 book ai didi

variables - Sass - 检查变量具有哪种类型的值

转载 作者:行者123 更新时间:2023-12-03 00:18:05 25 4
gpt4 key购买 nike

假设我有一个变量:

$var: 5px;

但在代码中的某个地方,其值已更改为可能的颜色数字emrm等.

有没有函数可以检测它的值类型?

@if is-color($var) { //do something }

我知道 sass 中没有 is-color 函数,但是还有其他方法可以做到这一点或函数吗?

最佳答案

来自 Sass 文档:

type_of($value)

Returns the type of a value.

Examples:

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 函数中可以互换)。

关于variables - Sass - 检查变量具有哪种类型的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23277103/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com