基本概况

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;
}

随机推荐

  1. 【tomcat】如何修改tomcat的默认项目

    我们知道,在Tomcat安装.配置.启动成功后在浏览器地址栏输入http://localhost:8080会访问到Tomcat的默认主页. 然后我们打开Tomcat的webapps目录时,会发现里面有 ...

  2. 夜话JAVA设计模式之适配器模式(adapter pattern)

    适配器模式:将一个类的接口,转换成客户期望的另一个接口,让不兼容的接口变成兼容. 1.类适配器模式:通过多重继承来实现适配器功能.多重继承就是先继承要转换的实现类,再实现被转换的接口. 2.对象适配器 ...

  3. Ubuntu中PPA源是什么

    以下内容转自https://imcn.me/ppa: PPA是Personal Package Archives首字母简写.翻译为中文意思是:个人软件包文档 只有Ubuntu用户可以用,而所有的PPA ...

  4. samba 奇怪问题

    有一个centos 7  samba服务器,配置如下: [root@proxy223 20150331]# cat /etc/samba/smb.conf [global] workgroup = W ...

  5. Performance Tunning - OCP

    This artical is forcused on Oracle 11g Release 2.  It is an summary from the OCP documentation. The ...

  6. Shell细小问题汇总

    Shell细小问题汇总 本文原文出处: http://blog.csdn.net/bluishglc/article/details/44276607 严禁不论什么形式的转载,否则将托付CSDN官方维 ...

  7. hdu 1728 逃离迷宫 bfs记步数

    题链:http://acm.hdu.edu.cn/showproblem.php?pid=1728 逃离迷宫 Time Limit: 1000/1000 MS (Java/Others)    Mem ...

  8. 一款炫酷Loading动画--载入失败

    简单介绍 上一篇文章一款炫酷Loading动画–载入成功.给大家介绍了成功动画的绘制过程,这篇文章将接着介绍载入失败特效的制作. 相比成功动画,有了前面的经验,失败动画的过程就显得比較简单了. 动画结 ...

  9. JDK部分源码阅读与理解

    本文为博主原创,允许转载,但请声明原文地址:http://www.coselding.cn/article/2016/05/31/JDK部分源码阅读与理解/ 不喜欢重复造轮子,不喜欢贴各种东西.JDK ...

  10. Codeforces Beta Round #67 (Div. 2)C. Modified GCD

    C. Modified GCD time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...