Less——less基本使用
基本概况
Less 是一门 CSS 预处理语言,它扩充了 CSS 语言,增加了诸如变量、混合(mixin)、函数等功能,让 CSS 更易维护、方便制作主题、扩充。Less 可以运行在 Node、浏览器和 Rhino 平台上。网上有很多第三方工具帮助你编译 Less 源码。
编译
1、在npm中输入以下语句,但是注意要更改文件位置
lessc style.less style.css
注释
1、// 双斜杠的注释 less是支持的而且这样的注释不会再编译之后出现在css中
2、/**/使用css的注释 less是支持的,编译的时候该注释会被保留
变量
1、@变亮名:具体值
2、经过nmp进行编译才能得到对于的css文件
@w: 100px;
@h: 50px;
@c: rgba(255, 255, 255, 0.3);
body {
width: @w;
height: @h;
background-color: @c;
}
===》编译:
C:\Users\Administrator>lessc E:\less\first\.less E:\less\first\.css
===》编译之后:
body {
width: 100px;
height: 50px;
background-color: rgba(255, 255, 255, 0.3);
}
混合
1、样式中可以混入类选择器和id选择器
.a, #b {
color: red;
}
.mixin-class {
.a();
}
.mixin-id {
#b();
}
===》编译后
.a, #b {
color: red;
}
.mixin-class {
color: red;
}
.mixin-id {
color: red;
}
请注意,当您调用mixin时,括号是可选的
.a(); //these lines do the same thing
.a;
2、可以不输出混合。你想用一个混合,这个混合只是在被引用的时候输出,自己不能作为类输出,你可以在它后面加括号。
.my-mixin {
color: black;
}
.my-other-mixin() {
background: white;
}
.class {
.my-mixin;
.my-other-mixin;
}
===》编译后
.my-mixin {
color: black;
}
.class {
color: black;
background: white;
}
3、混合中带有参数
.border-radius(@radius) {
-webkit-border-radius: @radius;
-moz-border-radius: @radius;
border-radius: @radius;
}
#header {
.border-radius(4px);
}
.button {
.border-radius(6px);
}
===》编译后
#header {
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
}
.button {
-webkit-border-radius: 6px;
-moz-border-radius: 6px;
border-radius: 6px;
}
混合中含有参数也有是默认值
.border-radius(@radius: 5px) {
-webkit-border-radius: @radius;
-moz-border-radius: @radius;
border-radius: @radius;
}
嵌套
#father {
width: 100px;
div {
width: 100px;
height: 50px;
ul {
width: 50px;
height: 50px;
li {
width: 50px;
height: 50px;
}
}
}
}
===》编译后
#father {
width: 100px;
}
#father div {
width: 100px;
height: 50px;
}
#father div ul {
width: 50px;
height: 50px;
}
#father div ul li {
width: 50px;
height: 50px;
}
选择器
1、嵌套中如果父元素与子元素有默认的空格,&可以取消空格,这为伪元素与交集选择器提供了可能
.content() {
width: 100px;
height: 100px;
}
div {
.content;
&:hover {
background-color: black;
}
&::after {
content: '';
display: block;
visibility: hidden;
height: 0;
line-height: 0;
clear: both;
}
}
===》编译后
div {
width: 100px;
height: 100px;
}
div:hover {
background-color: black;
}
div::after {
content: '';
display: block;
visibility: hidden;
height: 0;
line-height: 0;
clear: both;
}
随机推荐
- Neo4j ETL工具快速上手:简化从关系数据库到图数据库的数据迁移
注:本文系从https://medium.com/neo4j/tap-into-hidden-connections-translating-your-relational-data-to-graph ...
- 关于 Neo4j 属性个数的限制
关于 Neo4j 属性个数的限制 目前累积统计它有34.4亿个节点,344亿的关系,和6870亿条属性. 社区版,Neo4j对 数据库内 节点.关系 上的属性名个数是有限制的.数据库中至多存在687亿 ...
- 放大的X
Problem Description 请你编程画一个放大的’X’.如3*3的’X’应如下所示: X X XX X 5*5的’X’如下所示:X X X X X X XX X Input 输入数据第 ...
- ZOJ——3609 Modular Inverse
Modular Inverse Time Limit: 2 Seconds Memory Limit: 65536 KB The modular modular multiplicative ...
- C++学习之命名空间
在C++中,命名空间(namespace)的目的是为了防止名字冲突.每个命名空间是一个作用域,在所有命名空间之外,还存在一个全局命名空间(global namespace),全局命名空间以隐式的方式声 ...
- HDUPhysical Examination(贪心)
HDUPhysical Examination(贪心) 题目链接 题目大意:给N个队列,每一个队列在0时刻体检的时候完毕时间是ai.假设超过t(s),那么就是ai + t∗bi.问如何组合才干用最短的 ...
- layoutSubviews, setNeedsLayout, layoutIfNeeded
layoutSubviews总结 ios layout机制相关方法 - (CGSize)sizeThatFits:(CGSize)size- (void)sizeToFit——————- - (voi ...
- JAVA学习第二十一课(多线程(一)) - (初步了解)
放假在家,歇了好几天了,也没学习,今天学习一下多线程.找找感觉.后天就要回学校了.sad... PS:包 没有什么技术含量,会用就可以,日后开发就必需要会用啦,所以打算先放一放,先来多线程 一.多线程 ...
- org.apache.solr.handler.dataimport.DataImportHandlerException: Data Config problem: 对实体 "characterEn
解决的方法:在配置数据库连接是讲url里的特殊符号要做转义 jdbc:mysql://IP:3306/数据库名?useUnicode=true&characterEncoding=utf8 改 ...
- 2015南阳CCPC C - The Battle of Chibi DP树状数组优化
C - The Battle of Chibi Description Cao Cao made up a big army and was going to invade the whole Sou ...