LESS详解之混合(Mixins)初级
来源:互联网 发布:用什么能代替淘宝指数 编辑:程序博客网 时间:2024/05/17 04:33
在LESS中,有很多方式都可以称作混合。比如继承已有的样式,调用有参数的类名等。在LESS详解之混合都会为大家一一介绍的。
继承类名
在 LESS 中,可以定义一些通用的属性集为一个 class,然后在另一个 class 中去调用这些属性。如果我们现在需要在其他 class 中引入那些通用的属性集,那么我们只需要在任何 class 中调用就可以了。任何 CSS class, id 属性集都可以以同样的方式引入。小例子如下
LESS代码
.width {width:1232px;}#height {height:2980px;}.long {.width;.meng {#height;.width;}}
编译后的CSS代码
.width { width: 1232px;}#height { height: 2980px;}.long { width: 1232px;}.long .meng { height: 2980px; width: 1232px;}
带参数混合
在 LESS 中,你还可以像函数一样定义一个带参数的属性集合,然后在其他选择器中像调用它。小例子如下
LESS代码
.width (@width) {width:@width;}#height (@height) {height:@height;}.long {.width(20px);.meng {#height(30em);.width(50%);}}
编译后的CSS代码
.long { width: 20px;}.long .meng { height: 30em; width: 50%;}
隐藏属性继承
你也可以定义不带参数属性集合,如果你想隐藏这个属性集合,不让它暴露到 CSS 中去,但是你还想在其他的属性集合中引用,你会发现这个方法非常的好用。小例子如下
LESS代码
.width () {width:1234px;}#height () {height:5678px;}.long {.width();.meng {#height();.width();}}
编译后的CSS代码
.long { width: 1234px;}.long .meng { height: 5678px; width: 1234px;}
默认值混合
我们还可以像这样给参数设置默认值。有了默认值,我们可以不用设置属性值也能被调用。小例子如下
LESS代码
.width (@width : 2345px) {width:@width;}#height (@height : 6789px) {height:@height;}.long {.width();#height(753px);.meng {#height();.width(951px);}}
编译后的CSS代码
.long { width: 2345px; height: 753px;}.long .meng { height: 6789px; width: 951px;}
LESS详解之混合(Mixins)初级主要为大家介绍了一些LESS中有关混合(Mixins)的初级用法。只有掌握好了LESS混合中初级用法才更好的掌握一些比较高级的用法。希望LESS详解之混合(Mixins)初级能为大家有所帮助。
- LESS详解之混合(Mixins)初级
- LESS详解之混合(Mixins)中级
- LESS详解之混合(Mixins)高级
- SASS详解之混合(mixins)
- 4.Less混合(mixins)
- stylus之混合书写(Mixins)
- vue.js之mixins混合
- mixins混合
- less学习之混合
- mixins详解
- LESS详解之编译LESS
- Sass中的mixins混合使用
- Vue中的mixins(混合)使用方法
- LESS详解之变量(@)
- LESS详解之嵌套(&)
- LESS嵌套中的Mixins和classes
- Reactjs 之 mixins
- LESS详解之命名空间
- 网络学习笔记_WLAN
- mahout算法集
- start.s 代码分析
- 求无序数组中第二小的元素
- document.execCommand()的用法小记
- LESS详解之混合(Mixins)初级
- 用按钮控制图片左右滚动
- ascii码表和扩展表
- python下安装lxml
- jxl 读写excel
- hadoop 绑定到ipv4 .
- java web中传递中文参数问题
- 好消息:9省市试点跨省就医即时报销 (zz)
- Xdebug的使用说明