Less——less基本使用
基本概况
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;
}
随机推荐
- Windows中更新python模块的命令
最近写爬虫,突然发现自己的动态的User-Agent用不了了,所以想可能是新版本出来了,旧的版本用不了了,坏掉了. 一时间想不起用什么命令了,网上查了一下,发现很简单,所以记录一下方便以后忘了的时候快 ...
- 中庸之道(codevs 2021)
题目描述 Description 给定一个长度为N的序列,有Q次询问,每次询问区间[L,R]的中位数. 数据保证序列中任意两个数不相同,且询问的所有区间长度为奇数. 输入描述 Input Descri ...
- 我不喜欢的 Rust 特性 (之一) eager drop
struct Foo; impl Drop for Foo { fn drop(&mut self) { println!("drop"); } } fn main() { ...
- Prim算法和Dijkstra算法的异同
Prim算法和Dijkstra算法的异同 之前一直觉得Prim和Dijkstra很相似,但是没有仔细对比: 今天看了下,主要有以下几点: 1: Prim是计算最小生成树的算法,比如为N个村庄修路,怎么 ...
- 为什么Linux下的环境变量要用大写而不是小写
境变量的名称通常用大写字母来定义.实际上用小写字母来定义环境变量也不会报错,只是习惯上都是用大写字母来表示的. 首先说明一下,在Windows下是不区分大小写的,所以在Windows下怎么写都能获取到 ...
- go语言slice的理解
Golang slice yongsean 作者 2017.02.17 00:07 打开App 创建切片,len.cap.append b := make([]int, 5) println(le ...
- GPU 编程入门到精通(三)之 第一个 GPU 程序
博主因为工作其中的须要.開始学习 GPU 上面的编程,主要涉及到的是基于 GPU 的深度学习方面的知识,鉴于之前没有接触过 GPU 编程,因此在这里特地学习一下 GPU 上面的编程.有志同道合的小伙伴 ...
- Android应用程序相关的文件文件夹具体解释
一.方法介绍: 每一个Android应用程序都能够通过Context来获取与应用程序相关的文件夹,这些文件夹的功能各异,每一个文件夹都有自己的特点.有时候可能会搞混淆,本文结合andr ...
- LeetCode 349. Intersection of Two Arrays (两个数组的相交)
Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...
- mac 浏览器解决跨域问题
Chrome:命令行执行如下命令open -a Google\ Chrome --args --disable-web-security出现如下提示,说明已经开启: Safari: open -a ' ...