Less是一种动态的样式语言。Less扩展了CSS的动态行为,比如说,设置变量(Variables)、混合书写模式(mixins)、操作(operations)和功能(functions)等等,最棒的是,Less使用了现有的CSS语法,也就是说,你可以直接把你现成的样式文件“style.css”直接改成“style.less”,他也能正常工作。

编译less

1.使用js

<link rel="stylesheet/less" type="text/css" href="css/style.less" >
<script type="text/javascript" src="js/less-1.3.3.min.js" data-env="development" ></script >//网上可下载
2.Koala编译工具
koala是一个前端预处理器语言图形编译工具,支持Less、Sass、Compass、CoffeeScript,帮助web开发者更高效地使用它们进行开发。跨平台运行
官网地址http://koala-app.com/index-zh.html
3.使用第三方工具gulp grunt等
less语法 变量
//less
@color:#333;
header{
color:@color;
}
/*css*/
header{
color:#333333;
}

 混合--在 LESS 中我们可以定义一些通用的属性集为一个class,然后在另一个class中去调用这些属性

//less
.bd50{
border-radius: 50%;
}
.yuan{
width:100px;
height:100px;
background:red;
.bd50
}
/*css*/
.yuan{
width:100px;
height:100px;
background:red;
border-radius: 50%;
}
//html代码
<div class="yuan"></div>
 效果

带参数混合--像函数一样定义一个带参数的属性集合,然后在另一个class中去调用这些属性。

//less
/*classA:设置圆角角度为50px*/
.radius(@radius: 50px) {
border-radius: @radius;
-webkit-border-radius: @radius;
-moz-border-radius: @radius;
}
/*classB:设置阴影颜色大小*/
.boxShadow(@boxShadowColor:0 0 10px rgba(0, 204, 204, .5)){
-webkit-box-shadow:@boxShadowColor;
-moz-box-shadow:@boxShadowColor;
box-shadow:@boxShadowColor;
}
/*classC:调用A、B*/
.tableBorder{
border : 5px solid 5px solid #ffff00;
background: #ffc0cb;
width: 200px;
height: 200px;
padding: 0;
margin:0;
text-align: center;
line-height: 200px;
.boxShadow;
/*在classC中调用classA、B 带值带括号 括号内给值,执行括号内的数据*/
.radius();
}
/*css*/
.tableBorder {
border: 5px solid #ffff00;
background: #ffc0cb;
width: 200px;
height: 200px;
padding: 0px;
margin: 0px;
text-align: center;
line-height: 200px;
-webkit-box-shadow: 0 0 10px rgba(0, 204, 204, 0.5);
-moz-box-shadow: 0 0 10px rgba(0, 204, 204, 0.5);
box-shadow: 0 0 10px rgba(0, 204, 204, 0.5);
border-radius: 50px;
-webkit-border-radius: 50px;
-moz-border-radius: 50px;
}
 //html代码
<div class="tableBorder">我是一个带参数混合的正方形</div>

效果

 @arguments变量--@arguments包含了所有传递进来的参数. 如果你不想单独处理每一个参数的话就可以像这样写:

//less
.arguments{
width: @width200;
height: @width200;
margin: 30px;
.box-Shadow();
}
.box-Shadow(@x:0,@y:0,@blur:1px,@color: rgba(215, 22, 185, .5)){
//包含传进来的所有参数
box-shadow: @arguments;
-moz-box-shadow: @arguments;
-webkit-box-shadow: @arguments;
}
/*css*/
.arguments {
width: 200px;
height: 200px;
margin: 30px;
box-shadow: 0 0 1px rgba(215, 22, 185, 0.5);
-moz-box-shadow: 0 0 1px rgba(215, 22, 185, 0.5);
-webkit-box-shadow: 0 0 1px rgba(215, 22, 185, 0.5);
}
//html代码
<div class="arguments">arguments变量</div>

嵌套--可以在一个选择器中嵌套另一个选择器来实现继承,这样很大程度减少了代码量,并且代码看起来更加的清晰。

//less

 .list{
width: 100%;
padding: 0;
margin: 30px auto;
list-style: none;
li{
height: 30px;
line-height: 30px;
margin-bottom: 5px;
background: pink;
padding: 0 10px;
//这样写也可以 但是要进行更深层次的匹配 影响效率
/*a{
color: #666;
text-decoration: none;
padding-left: 20px;
}*/
}
a{
color: #666;
text-decoration: none;
//&:代表他的上一层选择器
&:hover{
color: #3a87ad;;
text-decoration: underline;
}
} span{
float: right;
}
}
/*css*/
.list {
width: 100%;
padding: 0;
margin: 30px auto;
list-style: none;
}
.list li {
height: 30px;
line-height: 30px;
margin-bottom: 5px;
background: pink;
padding: 0 10px;
}
.list a {
color: #5bc0de;
text-decoration: none;
}
.list a:hover {
color: #3a87ad;;
text-decoration: underline;
}
.list span {
float: right;
}
//html代码
<div class="qiantao">
<ul class="list">
<li><a href="#">这是一个测试嵌套的代码</a><span>2012-04-02</span></li>
<li><a href="#">这是二个测试嵌套的代码</a><span>2012-04-02</span></li>
<li><a href="#">这是三个测试嵌套的代码</a><span>2012-04-02</span></li>
</ul>
</div>

匹配模式--有些情况下,我们想根据传入的参数来改变混合的默认呈现,比如下面这个例子:

//less
//朝上
//宽度默认5,颜色默认灰色
.triangle(top,@w:100px,@c:#ccc){
border-width: @w;
border-color: transparent transparent @c transparent;
border-style: dashed dashed solid dashed;
}
//朝下
.triangle(bottom,@w:100px,@c:#ccc){
border-width: @w;
border-color:@c transparent transparent transparent;
border-style:solid dashed dashed dashed;
}
//朝左
.triangle(left,@w:100px,@c:#ccc){
border-width: @w;
border-color: transparent @c transparent transparent ;
border-style: dashed solid dashed dashed ;
}
//朝右
.triangle(right,@w:100px,@c:#ccc){
border-width: @w;
border-color: transparent transparent transparent @c ;
border-style: dashed dashed dashed solid;
}
//特殊匹配模式 不管匹配谁都会执行@_的内容
.triangle(@_,@w:100px,@c:#ccc){
width: 0px;
height: 0px;
overflow: hidden;
}
.sanjiao{
.triangle(left);
}
/*css*/
//由于调用的“left”,所以只会编译left的样式
.sanjiao {
border-width: 100px;
border-color: transparent #cccccc transparent transparent;
border-style: dashed solid dashed dashed ;
width: 0px;
height: 0px;
overflow: hidden;
}
 //html代码
<div class="sanjiao"></div>

less简介的更多相关文章

  1. ASP.NET Core 1.1 简介

    ASP.NET Core 1.1 于2016年11月16日发布.这个版本包括许多伟大的新功能以及许多错误修复和一般的增强.这个版本包含了多个新的中间件组件.针对Windows的WebListener服 ...

  2. MVVM模式和在WPF中的实现(一)MVVM模式简介

    MVVM模式解析和在WPF中的实现(一) MVVM模式简介 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在 ...

  3. Cassandra简介

    在前面的一篇文章<图形数据库Neo4J简介>中,我们介绍了一种非常流行的图形数据库Neo4J的使用方法.而在本文中,我们将对另外一种类型的NoSQL数据库——Cassandra进行简单地介 ...

  4. REST简介

    一说到REST,我想大家的第一反应就是“啊,就是那种前后台通信方式.”但是在要求详细讲述它所提出的各个约束,以及如何开始搭建REST服务时,却很少有人能够清晰地说出它到底是什么,需要遵守什么样的准则. ...

  5. Microservice架构模式简介

    在2014年,Sam Newman,Martin Fowler在ThoughtWorks的一位同事,出版了一本新书<Building Microservices>.该书描述了如何按照Mic ...

  6. const,static,extern 简介

    const,static,extern 简介 一.const与宏的区别: const简介:之前常用的字符串常量,一般是抽成宏,但是苹果不推荐我们抽成宏,推荐我们使用const常量. 执行时刻:宏是预编 ...

  7. HTTPS简介

    一.简单总结 1.HTTPS概念总结 HTTPS 就是对HTTP进行了TLS或SSL加密. 应用层的HTTP协议通过传输层的TCP协议来传输,HTTPS 在 HTTP和 TCP中间加了一层TLS/SS ...

  8. 【Machine Learning】机器学习及其基础概念简介

    机器学习及其基础概念简介 作者:白宁超 2016年12月23日21:24:51 摘要:随着机器学习和深度学习的热潮,各种图书层出不穷.然而多数是基础理论知识介绍,缺乏实现的深入理解.本系列文章是作者结 ...

  9. Cesium简介以及离线部署运行

    Cesium简介 cesium是国外一个基于JavaScript编写的使用WebGL的地图引擎,一款开源3DGIS的js库.cesium支持3D,2D,2.5D形式的地图展示,可以自行绘制图形,高亮区 ...

  10. 1.Hibernate简介

    1.框架简介: 定义:基于java语言开发的一套ORM框架: 优点:a.方便开发;           b.大大减少代码量;           c.性能稍高(不能与数据库高手相比,较一般数据库使用者 ...

随机推荐

  1. fdisk添加分区引起的Linux Error: 22: Invalid argument

    在Linux服务器(虚拟机)上使用fdisk添加分区.格式化分区后,遇到了Linux Error: 22: Invalid argument错误,操作步骤如下所示 [root@oracle-serve ...

  2. Symantec Backup Exec 2010 Agent For Linux安装

    以前写过一篇文章介绍过Symantec Backup Exec 2012 Agent For Linux安装安装,今天介绍一下Symantec Backup Exec 2010 Agent For L ...

  3. SQL SERVER 2008:内部查询处理器错误: 查询处理器在执行过程中遇到意外错误

       今天一个同事突然告诉我,以前跑得很正常的一个SQL语句,执行时突然报如下错误:         消息1222,级别16,状态18,第1 行         已超过了锁请求超时时段.        ...

  4. RAC异机恢复

    RAC异机恢复PDCL到PFCL: PNCL:RAC+ASM ,product env   db name:PNCL   instance:PDCL1 PDCL2 PFCL:RAC+ASM ,perf ...

  5. 从零自学Hadoop(08):第一个MapReduce

    阅读目录 序 数据准备 wordcount Yarn 新建MapReduce 示例下载 系列索引 本文版权归mephisto和博客园共有,欢迎转载,但须保留此段声明,并给出原文链接,谢谢合作. 文章是 ...

  6. python MySQLdb 对mysql基本操作方法

    #!/usr/bin/env python # -*- coding:utf-8 -*- import MySQLdb conn = MySQLdb.connect(host=',db='host') ...

  7. nginx 配置php

    安装php yum install php   yum install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php ...

  8. Ubuntu搭建Ruby On Rail环境

    受不了Ruby在Windows上的执行等待,转战至ubuntu linux下使用,为方便不同版本ruby的使用,采用了rvm安装Ruby on rails环境. 安装rvm //获取认证 gpg -- ...

  9. eclipse下maven项目保持原有目录结构配置resin运行环境

    maven项目用起来很方便,但是它的目录结构和eclipse的目录结构是有区别的,故而在eclipse下的maven项目,直接运行调试是有一些问题的. 为了方便maven项目的运行调试,因而也就有了像 ...

  10. [Django]网页中利用ajax实现批量导入数据功能

    url.py代码: url(r'^workimport/$', 'keywork.views.import_keywork', name='import_keywork') view.py代码: fr ...