Less初学
本文最后更新于 146 天前,其中的信息可能已经有所发展或是发生改变。

变量

@width: 10px;
@height:@width + 10px;

#header{
    width: @width;
    height: @height
}

混合

.bordered{
    border-top: dotted 1px black;
    border-bottom:solid 2px black;
}
#menu a {
    color: #111;
    .bordered();
}
.post a {
    color: red;
    .bordered();
}

嵌套

#header{
    color: black;
    .navigation {
        font-size: 12px;
    }
    .logo {
        width: 300px;
    }
}

等价于

#header {
    color: black;
}
#header .navigation {
    font-size: 12px;
}
#header .logo {
    width: 300px;
}

@规则 嵌套和冒泡

.component {
    width: 300px;
    @media (min-width: 768px) {
        width: 600px;
        @media (min-resolution: 192dpi) {
            background-image: url(/img/11.png);
        }
    }
    @media (min-width: 1280px) {
        width: 800px;
    }
}

等价于

.component {
  width: 300px;
}
@media (min-width: 768px) {
  .component {
    width: 600px;
  }
}
@media (min-width: 768px) and (min-resolution: 192dpi) {
  .component {
    background-image: url(/img/retina2x.png);
  }
}
@media (min-width: 1280px) {
  .component {
    width: 800px;
  }
}

运算*

转义

任何 ~"anything"~'anything' 形式的内容都将按原样输出,除非 interpolation

@min768: ~"(min-width: 768px)";
.element {
  @media @min768 {
    font-size: 1.2rem;
  }
}

编译为:

@media (min-width: 768px) {
  .element {
    font-size: 1.2rem;
  }
}

注意,从 Less 3.5 开始,可以简写为:

@min768: (min-width: 768px);
.element {
  @media @min768 {
    font-size: 1.2rem;
  }
}

函数

Less 函数手册

命名空间和访问符

#bundle(){
    .button{
        display: block;
        border: 1px solid black;
        &:hover {
            background-color: white;
        }
    }
    .tab {...}
    .citation {...}
}

#header a {
    color: orange;
    #bundle.button(); // 或者 #bundle > .button
}

如果不希望它们出现在输出的 CSS 中,例如 #bundle .tab,请将 () 附加到命名空间(例如 #bundle())后面

作用域

@var: red;

#page {
  @var: white;
  #header {
    color: @var; // white
  }
}
/**
 两者一样
*/
@var: red;
#page {
  #header {
    color: @var; // white
  }
  @var: white;
}

导入

@import "library"; // library.less
@import "typo.css";
本人本着学习交流的态度,恳请大家友好留言。
内容为个人笔记和记录,不保证其正确性,请慎用。
如有不足,望指正。如有侵权,请在留言板联系我。
文章作者:秃秃不是兔兔,如需引用,请标注原文地址:https://wangwangyz.site/archives/1166
暂无留言,来做第一个留言的人吧♥

发表评论 编辑评论


				

您的电子邮箱地址不会被公开,用于有回复时通知您。*为必填项

|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇