简单执行less

一、使用npm全局安装less:

npm install -g less

二、创建less文件

三、执行命令将less文件转换成css文件

lessc less/style.less css/style.css

 less语法概括

参考文档:http://www.1024i.com/demo/less/document.html

1、变量

变量是按需加载的,不必在使用前申明

// 变量
@f9color: #f938ab;
.container {
width: 100%;
height: 100%;
border: 1px solid @f9color;
}

变量

2、混合

// 混合
.clearBox {
margin:;
padding:;
box-sizing: border-box;
} body,html {
width: 100%;
height: 100%;
.clearBox; // 调用
} div {
.clearBox; // 调用
}

混合

3、嵌套

.clearfix {
display: block;
zoom:; &:after { // &表示当前选择器的父代
content: " ";
display: block;
font-size:;
height:;
clear: both;
visibility: hidden;
}
}

嵌套

4、嵌套指令并且冒泡

.container {
width: 100%;
height: 100%;
border: 1px solid @f9color; .screen-color {
width: 100px;
height: 100px;
@media screen {
background: @f9color;
@media (min-width: 768px) {
background: red;
}
}
} }

嵌套指令并且冒泡

5、import导入

// 放置位置无要求
// 通过Less依赖文件扩展名的方式区别对待不同的文件,.css文件直接按css导入不编译,其他类型文件包括没有扩展名的文件均按.less文件导入并编译 // 不带导入类型的:
@import "common.less";
// 带导入类型的:(只导入一次)
// 导入类型有:
// reference:使用Less文件但不输出
// inline:在输出中包含源文件但不加工它
// less:将文件作为Less文件对象,无论是什么文件扩展名
// css:将文件作为CSS文件对象,无论是什么文件扩展名
// once:只包含文件一次(默认行为)
// multiple:包含文件多次
@import (once) "common.less";

6、选择器、属性名、urls使用变量

// 选择器使用变量
@bg: bg;
.@{bg} {
background: @fff;
} // 编译后:
.bg {
background: #fff;
} // 属性使用变量
.position_info (@position: fixed; @propertyOne: top; @propertyOneVal: 0; @propertyTwo: left; @propertyTwoVal: 0) {
position: @position;
@{propertyOne}: @propertyOneVal;
@{propertyTwo}: @propertyTwoVal;
}
// 不传参数调用
.header {
.position_info; // 不传参数
}
// 编译后
.header {
position: fixed;
top: 0;
left: 0;
}
// 传参数调用
.header {
.position_info(absolute, bottom, 0, left, 20px); // 传参数
}
// 编译后
.header {
position: absolute;
bottom: 0;
left: 20px;
} // urls使用变量
@imageUrl: '../image';
.wrap {
background: url('@{imageUrl}/center.png') no-repeat center;
}
// 编译后
.wrap {
background: url('../image/center.png') no-repeat center;
}

7、避免编译符~

// 使用
@screen330: ~'(max-width: 330px)';
@screen380: ~'(max-width: 380px) and (min-width: 331px)';
.div {
width: 300px;
@media screen and @screen330 {
width: 100px;
}
@media screen and @screen380 {
width: 200px;
}
}
// 编译后
.div {
width: 300px;
}
@media screen and (max-width: 330px) {
.div {
width: 100px;
}
}
@media screen and (max-width: 380px) and (min-width: 331px) {
.div {
width: 200px;
}
}

8、带参数的属性,参数太多时使用@arguments

// box-shadow阴影设置,依次为水平阴影的位置、垂直阴影的位置,...表示除了前两个参数外后面可接收参数不限制个数
// 此属性接收0-N个参数,因为前两个参数已有默认值
// @arguments:传入参数太多时,可使用@arguments将全部参数都进行赋值
.box_shadow(@x: 0; @y: 0;...){
box-shadow: @arguments;
-webkit-box-shadow: @arguments;
-moz-box-shadow: @arguments;
-o-box-shadow: @arguments;
}

9、extend扩展

@bg: bg;
.@{bg} {
&:extend(.app); // &表示当前父选择器
background: @fff;
}
.app {
background: #fff;
}
// 编译后
.bg {
background: #fff;
}
.app,
.bg {
background: #fff;
}

简单如上,以后有新的体会再进行添加

随机推荐

  1. hadoop学习笔记411

    安装hadoop  1. 免秘钥  使用hadoop用户  ssh-keygen -t rsa  cp id_rsa.pub authorized_keys  cat id_rsa.pub>&g ...

  2. JIRA 破解文件研究(Win 7环境)

    最近再次回来研究 Win 7 下的 JIRA,按网上的很多方法去尝试,竟然无法正常安装! 经过几次的弯路尝试,终究还是成功了. 嗯,有必要总结一下: 发觉网上的很多破解方法都太老!不管是什么原因,在6 ...

  3. NFS原理详解

    NFS原理详解 摘自:http://atong.blog.51cto.com/2393905/1343950 2013-12-23 12:17:31 标签:linux NFS nfs原理详解 nfs搭 ...

  4. HighChar

    chart: { type:'bar', borderWidth:2, borderColor: '#CA5100', backgroundColor: '#90ED7D', shadow: { // ...

  5. Flutter起步之安装

    官网有介绍的这里就不说,主要有几个步骤: 镜像设置 下载flutter SDK(更新系统环境变量PATH,先不要运行flutter doctor,因为你还没有装android sdk和编辑器) and ...

  6. 笔记-JavaWeb学习之旅15

    Filter:过滤器 概念:当访问服务器的资源是,过滤器可以将请求拦截下来,完成一些特殊的功能 快速入门: 步骤: 定义一个类,实现接口Filter 复写方法 配置拦截路径 package com.d ...

  7. glassfish cluster 搭建

    http://blog.csdn.net/wych1981/article/details/8815150

  8. 黑马学习SpringMVC 基本开发步骤

  9. path不相等的子集,父级

    SELECT a.path,b.path from comm_department_temp a INNER JOIN comm_department_temp b on a.id=b.parent_ ...

  10. 12.创建高级联结---SQL

    一.使用表别名 SQL除了可以对列名和计算字段使用别名,还允许给表名起别名.这样做有两个主要理由: 缩短SQL语句: 允许在一条SELECT语句中多次使用相同的表. SELECT cust_name, ...