简单执行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. BootStrap 概念

    网格系统中的缩写; xs   extra  small sm  smal md  middle/medium lg    large

  2. 一个基于Tp3.2(thinkphp3.2)的工会管理系统

    该系统包括11个模块. 会员管理模块 奖惩管理模块 运动会管理模块 新闻管理模块 文档管理模块 经费管理模块 电子提案管理模块 用户管理模块 权限管理模块 系统管理模块 系统的登录 系统主页 这里只是 ...

  3. 天梯赛L3-001. 凑零钱(01背包记录物品)

    L3-001. 凑零钱 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 韩梅梅喜欢满宇宙到处逛街.现在她逛到了一家火星店里,发现 ...

  4. php如何运行

    这篇文章,研究一下php代码是如何解释和执行以及PHP脚本运行的生命周期. 概述 PHP服务的启动.严格来说,PHP的相关进程是不需要手动启动的,它是随着Apache的启动而运行的.当然,如果有需要重 ...

  5. 51nod1069【Nim取石子游戏】

    具体看:萌新笔记之Nim取石子游戏可以这么写: #include <bits/stdc++.h> using namespace std; typedef long long LL; in ...

  6. ue4 创建简易动画

    这个功能本来是在原动画基础上做调整用的,所以直接用来做动画并不是很合适,如果要做复杂动画,叠加的轨迹会非常多,不好用 (蒙皮好的)模型右键,创建一个动画合成 点开这个动画合成,创建动画序列(就是普通动 ...

  7. 51nod1109(bfs)

    题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1109 题意:中文题诶- 思路:可以用二叉树构建,根节点为 1, ...

  8. cf414B(dp)

    题目链接:http://codeforces.com/problemset/problem/414/B 题意:定义所有元素是其前一个元素的倍数的数列为good sequence,给出 n, 和 k,求 ...

  9. 小a和uim之大逃离(luogu P1373 dp)

    小a和uim之大逃离(luogu P1373 dp) 给你一个n*m的矩阵,其中元素的值在1~k内.限制只能往下和往右走,问从任意点出发,到任意点结束,且经过了偶数个元素的合法路径有多少个.在此题中, ...

  10. abap table control里面各种属性和事件的写法

    SAP中,Table Control是在Screen中用的最广泛的控件之一了,可以实现对多行数据的编辑. 简单来说,Table Control是一组屏幕元素在Screen上的重复出现,这就是它与普通屏 ...