less知识点总结(二)
变量:以@开头,由于变量只能定义一次,其本质就是“常量”。
@nice-blue: #5B83AD;
@light-blue: @nice-blue + #; #header {
color: @light-blue;
}
执行后:
#header {
color: #6c94be;
}
混合:可以将一个定义好的class A轻松的引入到另一个class B中,从而简单实现class B继承class A中的所有属性。我们还可以带参数地调用,就像使用函数一样。同样也可以使用#ids来做混合。
.bordered {
border-top: dotted 1px black;
border-bottom: solid 2px black;
}
#menu a {
color: #111;
.bordered;
}
.post a {
color: red;
.bordered;
}
编译如下:
.bordered {
border-top: dotted 1px black;
border-bottom: solid 2px black;
}
#menu a {
color: #111;
border-top: dotted 1px black;
border-bottom: solid 2px black;
}
.post a {
color: red;
border-top: dotted 1px black;
border-bottom: solid 2px black;
}
demo2如下:
#name {
border-top: dotted 1px black;
border-bottom: solid 2px black;
}
#menu a {
color: #111;
#name;
}
编译后如下:
#name {
border-top: dotted 1px black;
border-bottom: solid 2px black;
}
#menu a {
color: #111;
border-top: dotted 1px black;
border-bottom: solid 2px black;
}
运算:
任何数字、颜色或者变量都可以参与运算。下面是一组案例:
@base: 5%;
@filler: @base * 2;
@other: @base + @filler; color: #888 / 4;
background-color: @base-color + #111;
height: 100% / 2 + @filler;
作用域(scope):
Scope in Less is very similar to that of programming languages. Variables and mixins are first looked for locally, and if they aren't found, the compiler will look in the parent scope, and so on.(less的作用域和编程的语言的作用域非常类似,变量和混合首先在当前的作用域查找,找不到,编译器就向父级作用域查找)
@var: red;
#page {
@var: white;
#header {
color: @var; // white
}
}
编译后如下:
#page #header {
color: #ffffff;
}
导入(Importe)
和你预期的工作方式一样。你可以导入一个 .less 文件,此文件中的所有变量就可以全部使用了。如果导入的文件是 .less 扩展名,则可以将扩展名省略掉:
@import "library"; // library.less
@import "typo.css";
URLs
// Variables
@images: "../img"; // 用法
body {
color: #444;
background: url("@{images}/white-sand.png");
}
编译后:
body {
color: #444;
background: url("../img/white-sand.png");
}
混合二(Mixin)—— "Mix-in" properties from existing styles
You can mix-in class selectors and id selectors, e.g.
.a, #b {
color: red;
}
.mixin-class {
.a();
}
.mixin-id {
#b();
}
编译后:
.a,
#b {
color: red;
}
.mixin-class {
color: red;
}
.mixin-id {
color: red;
}
当使用混合的时候,圆括号可以省略(Notice that when you call the mixin, the parenthesis are optional)
.a(); //these lines do the same thing
.a;
不输出混合(not outputting the mixin)
如果创建了混合,但是不想输出它,就在混合后面加一个圆括号。
.my-mixin {
color: black;
}
.my-other-mixin() {
background: white;
}
.class {
.my-mixin;
.my-other-mixin;
}
编译后:
.my-mixin {
color: black;
}
.class {
color: black;
background: white;
}
带参数的Mixin--
1. Mixin可以带参数,这个参数可以是变量,直接传递到选择器里面。
.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;
}
#header {
.border-radius;
}
编译后:
#header {
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
}
2. 可以直接使用命名的参数,引入变量:
.mixin(@color: black; @margin: 10px; @padding: 20px) {
color: @color;
margin: @margin;
padding: @padding;
}
.class1 {
.mixin(@margin: 20px; @color: #33acfe);
}
.class2 {
.mixin(#efca44; @padding: 40px);
}
编译后:
.class1 {
color: #33acfe;
margin: 20px;
padding: 20px;
}
.class2 {
color: #efca44;
margin: 10px;
padding: 40px;
}
3. 多个参数传参数
.mixin(@color; @padding:2) {
color-2: @color;
padding-2: @padding;
}
div {
.mixin(#008000;4px);//使用分号
}
p {
.mixin(red);
}
table{
.mixin(#008000,4px);//使用逗号
}
编译后:
div {
color-2: #008000;
padding-2: 4px;
}
p {
color-2: red;
padding-2: 2;
}
table {
color-2: #008000;
padding-2: 4px;
}
less知识点总结(二)的更多相关文章
- java基础知识点补充---二维数组
#java基础知识点补充---二维数组 首先定义一个二维数组 int[][] ns={ {1,2,3,4}, {5,6,7,8}, {9,10,11,12}, {13,14,15,16} }; 实现遍 ...
- 前端新人学习笔记-------html/css/js基础知识点(二)
4月7日学到的知识点: 一:<img src="1.png" alt="美女"/> alt是给图片添加介绍,当图片没加载出来时,会直接显示a ...
- Java 面试知识点解析(二)——高并发编程篇
前言: 在遨游了一番 Java Web 的世界之后,发现了自己的一些缺失,所以就着一篇深度好文:知名互联网公司校招 Java 开发岗面试知识点解析 ,来好好的对 Java 知识点进行复习和学习一番,大 ...
- 一些LinuxC的小知识点(二)
一.read系统调用 系统调用read的作用是:从与文件描述符filedes相关联的文件里读入nbytes个字节的数据,并把它们放到数据区buf中.它返回实际读入的字节数.这可能会小于请求 ...
- JS知识点整理(二)
前言 这是对平时的一些读书笔记和理解进行整理的第二部分,第一部分请前往:JS知识点整理(一).本文包含一些易混淆.遗漏的知识点,也会配上一些例子,也许不是很完整,也许还会有点杂,但也许会有你需要的,后 ...
- vue.js 知识点(二)
关于vue看到有很多的知识点和react有很多相近的地方,比如说路由还有一些简单的运用,但是又有一些不同,比如格式.还有写法的一些不同! 所以在这里我总结一下关于vue 关于路由的一些运用: 路由: ...
- 笔记9:winfrom的一些知识点(二)
一.新建,和删除文件夹 private void button4_Click(object sender, EventArgs e) { Directory.Delete(@"F:\&quo ...
- .NET知识点总结二(笔记整合)
19.什么是类型? 用来定义某一种数据在内存里开辟空间的大小,还可以预置操作此种类型数据的相关方法 20.this关键字在方法中使用时所代表的含义 this指的是当前类的对象,或者父类的类的对象(ba ...
- PMP知识点(二)——三点估算的两种方法对活动持续时间估算的影响和如何取舍
一.准备工作 活动持续时间的估算属于PMBOK中第六章项目时间管理中第五节6.6估算活动持续时间的内容. 三点估算是6.5和7.2(估算成本)中应用到的一种工具和技术.数据流向图参考如下: 其应用到的 ...
- Java基础知识点(二)
前言:Java的基础知识点不能间断. 1.Array和ArrayList的区别 关于Array的用法,参看:http://blog.csdn.net/b_11111/article/details/5 ...
随机推荐
- Nginx 的常用命令
nginx命令,先来一波基本操作: start nginx // 启动Nginx nginx -t // 测试配置文件 nginx -v // 查看Nginx版本 nginx -V // 查看Ngin ...
- ArcGIS 10.2 for Server 集群部署
ArcGIS 10.2 for Server 具有很灵活的体系结构,而 ArcGIS 10.2 forServer site 可以包含一台或多台安装 GIS Server 的机器,这些参与ArcGI ...
- Java虚拟机系列(三)---内存溢出情况及解决方法
因为Java虚拟机内存有堆内存.方法区.虚拟机栈.本地方法栈和程序计数器五部分组成,其中程序计数器是唯一一块不会发生内存溢出异常的内存区,所以只有四类内存区可能发生内存溢出异常,其中虚拟机栈和本地方法 ...
- java类增强方式
我理解的增强类即是对类进行功能性扩展,除了网上常规的3种方法( 1.继承或者实现接口:特点是被增强对象不能变,增强的内容不能变. 2.装饰着模式:特点是被增强对象可变,但增强内容不可变. 3.动态代理 ...
- PHP基于openssl实现的非对称加密操作
使用非对称加密主要是借助openssl的公钥和私钥,用公钥加密私钥解密,或者私钥加密公钥解密. 1.安装openssl和php的openssl扩展 2.生成私钥:openssl genrsa 用于生成 ...
- 数据库访问技术 odbc dao rdo uda jet oledb
一.UDA(UniversalDataAccess) 这是微软提供的通用数据访问策略.包括ADO.OLEDB和ODBC.它不光提供了数据库的访 问能力,对于其它的数据存储技术也同样支持,如目录服务.E ...
- virtualenv简单使用
前提 在开发过程中,经常需要使用各种第三方库,而且python又提供了pip,easy_install等工具来简化库的安装,所以很容易就会在系统python的site-packages目录中装满各种各 ...
- Eclipse:Eclipse插件开发全套教程
分享是美德,作者为Eclipse核心工程师之一,全英文版,有不明白的地方欢迎探讨和咨询. http://www.vogella.com/tutorials/eclipse.html
- PHP--时间格式处理
Ymd格式转Y-m-d或转成时间戳将Ymd格式如19930811转成1993-08-11格式 date('Y-m-d',strtotime('19930811') 将Ymd格式如19930811转成时 ...
- 【笔记】LR响应时间
事务:是指在客户端做一种或多种的业务所需要的操作集. 事务响应时间:是通过记录用户请求的开始时间和服务器返回内容到客户时间的差值来计算用户响应时间. 响应时间是服务器返回和用户请求之间的时间差,那么得 ...