less 的一些基础知识(简单易学)
来源:互联网 发布:怎么下载mac office 编辑:程序博客网 时间:2024/04/29 23:15
今天我来总结一下less的一些基础知识。非常简单,一般看半天基本就可以上手。
一、less 定义常量、混合、带参数的混合、@arguments。
1. less可以定义常量:
@blue:#846; // 颜色@width:200px; //宽度.Div{ .width; height:400px; background:@blue;}
解析成css:
Div{ width:200px; height:400px; background:#846;}
2.混合、带参数的混合
混合:
.widthHeight{width:300px;height:300px}.Div{ .widthHeight; background:red;}
解析成:
.Div{ width:300px; height:300px; background:red;}
带参数的混合:
.border-radius (@raduis){ border-radius:@raduis; -ms-border-radius:@raduis; -webkit-border-radius:@raduis; -moz-border-radius:@raduis;}.Div{ width:200px; height:400px; .border-radius(60px); }
解析成:
.Div{ width:200px; height:400px; .border-radius(60px); border-radius:60px; -ms-border-radius:60px; -webkit-border-radius:60px; -moz-border-radius:60px; }
如果你想有参数有默认值得话可以这样写
.border-radius (@raduis:10px){ border-radius:@raduis; -ms-border-radius:@raduis; -webkit-border-radius:@raduis; -moz-border-radius:@raduis;}
3.@arguments
@arguments 中存储着所有的参数,如果你不想每个参数都写一遍可以用它。
.border (@w:10px,@type:solid, @colr:#938413) { border:@arguments;}.Div{ width:200px; height:400px; background:blue; .border(20px,solid,#983493); }
解析成:
.Div{ width:200px; height:400px; background:blue; .border(20px, solid, #983493); }
4.地址拼接
@base-url: "http://www.webxiaoma.com";background-image: url("@base-url/images/bg.png");
二、less 嵌套规则。
我们可以这样嵌套:
.Div{ height:400px; background:@blue; font-size:20px; color:white; .myP{ width:200px; height:200px; line-height:200px; &:hover{ color:red; } } }
解析成:
.Div{ height:400px; background:@blue; font-size:20px; color:white; } .Div .myP{ width:200px; height:200px; line-height:200px; font-size:20px; color:white;} .Div .myP:hover{ color:red;}
① 这样写 类名为 .myP 的元素会继承 类名为 .Div 元素的一些样式 (类名为 .myP 的元素 是类名为 .Div 元素的子元素)
② 一些伪类元素 如 after before hover link active 等用特殊字符 &
这样写
&:hover{ color:red; }
另一个
.Div{ height:400px; background:@blue; font-size:20px; color:white; .myP{ width:200px; height:200px; line-height:200px; &:hover{ color:red; } } }.DivTwo{ width:100px; height:100px; .Div>.myP // 直接嵌套}
三、less 的作用域。
1.less 的作用域 是逐级向上查找的。也就是说,在查找css样式时,如果在自己作用域中没有查到,会想父级去查找,如果还没有找到,会一直向上去查找,直到找到为止。
四、Importing
1.在less 文件中我们可以引入额外的less文件:
@import "header.less";// 或者是@import "header";
2.如果你想不让less 编译css文件,直接将文件后缀改为 .css
header.css
阅读全文
0 0
- less 的一些基础知识(简单易学)
- 简单易学的十道菜
- 简单易学的十道菜
- 简单易学的highcharts
- 【Linux】-----简单易学的安装
- 【Linux】-----简单易学的安装
- 对LESS的自我理解 和一些简单的LESS封装
- 绝对简单易学的PHP入门教程
- 简单易学的葱油饼制作全过程
- 简单易学的技术教程索引
- 简单易学的移动开发appcan
- 100道简单易学的素菜
- 简单易学的动画切换页面
- 简单的LESS Tutorial
- less的简单使用
- less基础知识
- java中一些简单的基础知识,温故而知新
- 一些简单的java基础知识复习。
- Fiddler修改指定request的response报文方法
- windows安装jenkins
- 猎头、培训与咨询的价值(2)【补1】——北漂18年(93)
- Android资源管理框架(Asset Manager)
- Java double转long方法
- less 的一些基础知识(简单易学)
- android暗码
- mips寄存器介绍
- tf.argmax()
- C#学习笔记(八)—–LINQ查询的基础知识(中)
- C对文件的一些操作(孙鑫vc++的阅读笔记)
- 分布式系统接口幂等性
- js 获取当前时间 年月日
- Android Intent使用举例