- 语言特性
- LESS - 嵌套规则
- LESS - 嵌套指令和冒泡
- LESS - 运算
- LESS - 转义
- LESS - 函数
- LESS - 命名空间和访问器
- LESS - 作用域
- LESS - 注释
- LESS - 导入
- LESS - 变量
- LESS - 扩展
- LESS - Mixin
- LESS - 参数化Mixin
- LESS - Mixin作为函数
- LESS - 向Mixin传递规则集
- LESS - 导入指令
- LESS - 导入选项
- LESS - Mixin 保护
- LESS - CSS 保护
- LESS - 循环
- LESS - 合并
- LESS - 父选择器
- 函数
- LESS - 其他函数
- LESS - 字符串函数
- LESS - 列表函数
- LESS - 数学函数
- LESS - 类型函数
- LESS - 颜色定义函数
- LESS - 颜色通道函数
- LESS - 颜色运算
- LESS - 颜色混合函数
- 用法
- LESS - 命令行用法
- 在浏览器中使用LESS
- LESS - 浏览器支持
- LESS - 插件
- LESS - 程序化用法
- LESS - 在线编译器
- LESS - 图形用户界面
- LESS - 编辑器和插件
- LESS - 第三方编译器
- LESS - 框架
- LESS 有用资源
- LESS - 快速指南
- LESS - 有用资源
- LESS - 讨论
LESS - 类型函数
本章我们将了解类型函数在LESS中的重要性。它们用于确定值的类型。
下表显示了LESS中使用的类型函数。
| 序号 | 类型函数及描述 | 示例 |
|---|---|---|
| 1 | isnumber 它以一个值作为参数,如果该值是数字则返回true,否则返回false。 |
isnumber(1234); // true
isnumber(24px); // true
isnumber(7.8%); // true
isnumber(#fff); // false
isnumber(red); // false
isnumber("variable"); // false
isnumber(keyword); // false
isnumber(url(...)); // false
|
| 2 | isstring 它以一个值作为参数,如果该值是字符串则返回true,否则返回false。 |
isstring("variable"); // true
isstring(1234); // false
isstring(24px); // false
isstring(7.8%); // false
isstring(#fff); // false
isstring(red); // false
isstring(keyword); // false
isstring(url(...)); // false
|
| 3 | iscolor 它以一个值作为参数,如果该值是颜色则返回true,否则返回false。 |
iscolor(#fff); // true
iscolor(red); // true
iscolor(1234); // false
iscolor(24px); // false
iscolor(7.8%); // false
iscolor("variable"); // false
iscolor(keyword); // false
iscolor(url(...)); // false
|
| 4 | iskeyword 它以一个值作为参数,如果该值是关键字则返回true,否则返回false。 |
iskeyword(keyword); // true
iskeyword(1234); // false
iskeyword(24px); // false
iskeyword(7.8%); // false
iskeyword(#fff); // false
iskeyword(red) ; // false
iskeyword("variable");// false
iskeyword(url(...)); // false
|
| 5 | isurl 它以一个值作为参数,如果该值是URL则返回true,否则返回false。 |
isurl(url(...)); // true
isurl(keyword); // false
isurl(1234); // false
isurl(24px); // false
isurl(7.8%); // false
isurl(#fff); // false
isurl(red) ; // false
isurl("variable"); // false
|
| 6 | ispixel 它以一个值作为参数,如果该值是像素单位的数字则返回true,否则返回false。 |
ispixel(24px); // true
ispixel(1234); // false
ispixel(7.8%); // false
ispixel(keyword); // false
ispixel(#fff); // false
ispixel(red) ; // false
ispixel("variable"); // false
ispixel(url(...)); // false
|
| 7 | isem 它以一个值作为参数,如果该值是em单位的值则返回true,否则返回false。 |
isem(0.5em); // true
isem(1234); // false
isem(24px); // false
isem(keyword); // false
isem(#fff); // false
isem(red) ; // false
isem("variable"); // false
isem(url(...)); // false
|
| 8 | ispercentage 它以一个值作为参数,如果该值是百分比则返回true,否则返回false。 |
ispercentage(7.5%); // true
ispercentage(url(...)); // false
ispercentage(keyword); // false
ispercentage(1234); // false
ispercentage(24px); // false
ispercentage(#fff); // false
ispercentage(red) ; // false
ispercentage("variable"); // false
|
| 9 | isunit 如果值为指定单位的数字,则返回true;如果值不是指定单位的数字,则返回false。 |
isunit(10px, px); // true
isunit(5rem, rem); // true
isunit(7.8%, '%'); // true
isunit(2.2%, px); // false
isunit(24px, rem); // false
isunit(48px, "%"); // false
isunit(1234, em); // false
isunit(#fff, pt); // false
isunit("mm", mm); // false
|
| 10 | isruleset 它以一个值作为参数,如果该值是规则集则返回true,否则返回false。 |
@rules: {
color: green;
}
isruleset(@rules); // true
isruleset(1234); // false
isruleset(24px); // false
isruleset(7.8%); // false
isruleset(#fff); // false
isruleset(blue); // false
isruleset("variable"); // false
isruleset(keyword); // false
isruleset(url(...)); // false
|
广告