基本概况

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. python中实现将普通字典dict转换为java中的treeMap

    上代码: from heapq import heappush,heappop from collections import OrderedDict def toTreeMap(paramMap): ...

  2. Win32编程API 基础篇 -- 1.入门指南 根据英文教程翻译

    入门指南 本教程是关于什么的 本教程的目的是向你介绍使用win32 API编写程序的基础知识(和通用的写法).使用的语言是C,但大多数C++编译器也能成功编译,事实上,教程中的绝大多数内容都适用于任何 ...

  3. Linux运行级别研究(转)

    Linux系统中的运行级别 7种运行级别 运行级别(Runlevel)指的是Unix或者Linux等类Unix操作系统的运行模式,不同的运行模式下系统的功能也有所有不同.Linux 系统下通常分为7种 ...

  4. [Angular] New in V6.1

    Router Scroll Position Restoration: remember and restore scroll position as the user navigates aroun ...

  5. [学习笔记]JavaScript基础

    JavaScript概述 1. JavaScript定义 JavaScript是Netscape公司开发的一种基于对象和事件驱动的脚本语言.它是弱类型语言.仅仅能由浏览器解释运行. 当中: 脚本语言: ...

  6. poj-1635 Subway tree systems(推断两个有根树是否同构)-哈希法

    Description Some major cities have subway systems in the form of a tree, i.e. between any pair of st ...

  7. Java - 对象(object) 具体解释

    对象(object) 具体解释 本文地址: http://blog.csdn.net/caroline_wendy/article/details/24059545 对象(object)的实例能够是 ...

  8. Android 淘宝搜索记录分析及千牛数据库名称关联

    一 taobao搜索关键字分析1.导出淘宝数据文件夹.2.搜索search 找到search文件夹.查看里面可疑文件如history_8d4255cc9c9199c6ec3be940936986b9. ...

  9. restrict关键字

    值得注意的是,一旦你决定使用restrict来修饰指针,你必须得保证它们之间不会互相重叠,编译器不会替你检查. 关键字restrict有两个读者.一个是编译器,它告诉编译器可以自由地做一些有关优化的假 ...

  10. telnet端口问题

    今天测试发现telnet 一个端口不通,开始还以为是服务开放这个端口有问题,后来才发现这个端口是udp的.而telnet下层走的tcp协议,自然无法测试那些tcp的端口. 而之前下意识里还总以为都可以 ...