首页 > 其他 > 详细

Less 入门

时间:2021-01-19 23:41:18      阅读:53      评论:0      收藏:0      [点我收藏+]

但行好事,末问前程

CSS 预处理器

Less、 Sass 、 stylus

技术分享图片
Less 官网

<link rel="stylesheet/less" type="text/css" href="styles.less" />


<script src="less.js" type="text/javascript"></script>

Less使用

嵌套应用

Less编译工具

koala官网:www.koala-app.com
推荐 VScode 编译插件 EASYLess

Less注释

以// 开头的注释,不会被编译到Css文件中
以/* */包裹的注释会被编译到Css文件中

Less 变量

注意变量为延迟加载

1、 普通属性值

@color: pink ;


.inner {
    background : @color  ; 
} 

2、自行的属性名或选择器名作为变量(不常用)

技术分享图片
3、 作为URL
@{url}

Less 嵌套规则

1、 结构层次嵌套
2、 & 的使用(避免空格)

Less中的混合 (重要)

混合就是将一系列属性从一个规则集引入到另一个规则集的方式
1.普通混合
2.不带输出的混合
3.带参数的混合
4.带参数并且有默认值的混合
5.带多个参数的混合
6.命名参数
7.匹配模式
8. arguments变量

带参数并且有默认值的混合
技术分享图片

*{
    margin: 0;
    padding: 0;
}
.juzhong(@w:100px,@h:100px,@c:pink){
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    top: 0;
    margin: auto;
    width: @w;
    height: @h;
    background: @c;
}
#wrap{
    position: relative;
    margin: 0 auto;
    width: 400px;
    height: 600px;
    border: 1px solid;
}



#box1{
    .juzhong();
    z-index: 1;
}
#box2{
    .juzhong(@h:200px;@c:deeppink;);
}
 

arguments变量

鸡肋,实参类似于数组
技术分享图片
简化下述参数

技术分享图片

Less 继承(重要)

Less 代码
技术分享图片

*{
    margin: 0;
    padding: 0;
}
.common:hover{
    background: pink;
}
.common{
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    top: 0;
    margin: auto;
}
.juzhong(@w:100px,@h:100px,@c:pink){
    &:extend(.common all);
    width: @w;
    height: @h;
    background: @c;
}
#wrap{
    position: relative;
    margin: 0 auto;
    width: 400px;
    height: 600px;
    border: 1px solid;
}

#box1{
    .juzhong();
    z-index: 1;
}
#box2{
    .juzhong(@h:200px;@c:deeppink;);
}

编译后CSS 代码

* {
  margin: 0;
  padding: 0;
}
.common:hover,
#box1:hover,
#box2:hover {
  background: pink;
}
.common,
#box1,
#box2 {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  top: 0;
  margin: auto;
}
#wrap {
  position: relative;
  margin: 0 auto;
  width: 400px;
  height: 600px;
  border: 1px solid;
}
#box1 {
  width: 100px;
  height: 100px;
  background: #ffc0cb;
  z-index: 1;
}
#box2 {
  width: 100px;
  height: 200px;
  background: #ff1493;
}

Less 避免编译

less 语法
说明: 带上~“ ” 表示不编译内部代码
calc() 计算方法

*{
    margin: 0;
    padding: 0;
}
#wrap{
    width:~"calc(200px + 700px)";
}

编译结果

css

* {
  margin: 0;
  padding: 0;
}
#wrap {
  width: calc(200px + 700px);
}

Less 入门

原文:https://www.cnblogs.com/lzhCreate/p/14300572.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!