基本概况

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. Jeecg+fixflow,工作流框架分享

    工作流引擎使用fixflow. 动态表达使用jeecg. 不多说直接上源码. 注:本人使用的jdk为6.0.mysql.tomcat6.0 其中fixflow-expand 为eclips流程设计核心 ...

  2. [bzoj1507][Usaco2009 Hol]Transmission Delay 传输谍延时_动态规划

    Transmission Delay 传输谍延时 bzoj-1581 Usaco-2009 Hol 题目大意:题目链接. 注释:略. 想法: 动态规划. 首先我们考虑从后往前dp.(最近好多题都是从后 ...

  3. [bzoj1563][NOI2009]诗人小G(决策单调性优化)

    题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1563 分析: 首先可得朴素的方程:f[i]=min{f[j]+|s[j]-j-s[i] ...

  4. MySQL Workbench查看和修改表字段的Comment值

    查看: 选择单个表->[右键]->[Table Inspector] 再选择Columns选项卡即可,把表格拉倒最后一列. 编辑: 选择单个表->[右键]->[Alter Ta ...

  5. 16、Java并发性和多线程-死锁

    以下内容转自http://ifeve.com/deadlock/: 死锁是两个或更多线程阻塞着等待其它处于死锁状态的线程所持有的锁.死锁通常发生在多个线程同时但以不同的顺序请求同一组锁的时候. 例如, ...

  6. Manthan, Codefest 16 C

    建trie树,刚好字符串是反向的,直接在原图上向前搜索就OK了……………… 可怜的我竟然用了RK来hash,在test67那里T了…… 贴个RK的 #include <iostream> ...

  7. hdoj1106排序

     /* Problem Description 输入一行数字,假设我们把这行数字中的'5'都看成空格. 那么就得到一行用空格切割的若干非负整数 (可能有些整数以'0'开头.这些头部的'0'应该被忽 ...

  8. javascript 变量声明 和 作用域

    变量的声明 1.变量声明具有提升机制,Javascript在执行时,会把所有的声明都提升到当前作用域前面. 先看一下下面的例子: (function(){ alert(b)//b is not def ...

  9. [Java] 实验6參考代码

    1. 大家的.java程序都须要在一个"缺省包"(default package)下编写\执行\提交,不要去命名新的package     - 系统不支持package contr ...

  10. Asp.NET之对象学习

    一.总述 二.具体介绍 1.Request对象 Request对象是用来获取client在请求一个页面或传送一个Form时提供的全部信息,这包含可以标识浏览器和用户的HTTP变量,存储在client的 ...