美文网首页
2017-3-24 less

2017-3-24 less

作者: 阿苏菇凉 | 来源:发表于2017-03-24 19:05 被阅读0次

CSS Guards(CSS保护)

LESS:

& when (@my-option = true) {
  button {
    color: white;
  }
  a {
    color: blue;
  }
}

Import Directives (导入准则)

LESS:

.a {
  color: green;
}
@import (multiple) "style.less";
@import (multiple) "style.less";

CSS:

.a {
  color: green;
}
.a {
  color: green;

Misc Functions (杂项函数)

LESS:

.mixin(1)                   {x: 11}
.mixin(2)                   {y: 22}
.mixin(@x) when (default()) {z: @x}

div {
  .mixin(3);
}

div.special {
  .mixin(1);
}

CSS:

div {
  z: 3;
}
div.special {
  x: 11;
}

LESS:

.mixin(@value) when (ispixel(@value)) {width: @value}
.mixin(@value) when not(default())    {padding: (@value / 5)}
div-1 {
  .mixin(100px);
}
div-2 {
  .mixin(300px);
}

CSS:

div-1 {
  width: 100px;
  padding: 20px;
}
div-2 {
  width: 300px;
  padding: 60px;
}

String Functions (字符串函数)

replace (替换)

  • string: 搜索和替换用的字符串.
  • pattern:一个字符串或者能搜索的正则表达式.
  • replacement: 匹配模式成功的替换字符串.
  • flags: (可选的) 正则表达式匹配标识(全匹配还是…).
    LESS:
replace("Hello, Mars?", "Mars\?", "Earth!");
replace("One + one = 4", "one", "2", "gi");
replace('This is a string.', "(string)\.$", "new $1.");
replace(~"bar-1", '1', '2');

Color Definition Functions (颜色定义函数)

1、通过十进制红色,绿色,蓝色,以及 alpha 四种值 (RGBA) 创建带alpha透明的颜色对象。

@red: 整数 0-255 或百分比 0-100%.
@green: 整数 0-255 或百分比 0-100%.
@blue: 整数 0-255 或百分比 0-100%.
@alpha: 数字 0-1 或百分比 0-100%.

2、通过色相 (hue),饱和度 (saturation),亮度 (lightness) 三种值 (HSL) 创建不透明的颜色对象。

@hue: 整数 0-360 表示度数
@saturation: 整数 0-100% 或是数字 0-1
@lightness: 整数 0-100% 或是数字 0-1

练习
less:

@import "state.less"; 
@import "layout.less"; 
@import "base.less"; 
.f-l {
    float: left;
}

.f-r {
    float: right;
}

#box-wrap {
    .banner {
        padding-top: 70px;
        margin-bottom: 80px;
        .container {
            width: 970px;
            .navbar {
                margin: 0 15px;
                .col-nav-l {
                    width: 25%;
                    .f-l;
                    a {
                        width: 52px;
                        height: 30px;
                        padding: 0;
                        font-size: 18px;
                        display: block;
                    }
                }
                .col-nav-c {
                    width: 75%;
                    .f-l;
                    ul {
                        display: table;
                        margin-bottom: 0;
                        padding-left: 0;
                        text-align: center;
                        li {
                            font-size: 20px;
                            display: inline-block;
                            position: relative;
                            margin-left: 50px;
                            .f-l;
                        &:first-child {
                            a {
                                    border-bottom: 2px solid #52d3aa;
                            }
                        }
                            a {
                                color: #000;
                                font-weight: 400;
                                &:hover {
                                    color: #989898;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    .intro {
        width: 970px;
        padding-bottom: 5em;
        .intro-txt {
            width: 60%;
            margin: 0 auto;
            h2 {
                font-size: 30px;
                line-height: 1.5em;
                margin-bottom: 30px;
                text-align: center;
            }
        }
    }
}

CSS:

#header {
  width: 100%;
  height: 90px;
  margin: 0 auto;
  background-color: #eeeff0;
  margin: 0;
  padding: 0;
}
#box-wrap {
  background-color: #fff;
  max-width: 1000px;
  margin: 0 auto;
}
.fix {
  margin: 0;
  padding: 0;
}
ul li {
  list-style-type: none;
}
a {
  text-decoration: none;
}
.f-l {
  float: left;
}
.f-r {
  float: right;
}
#box-wrap .banner {
  padding-top: 70px;
  margin-bottom: 80px;
}
#box-wrap .banner .container {
  width: 970px;
}
#box-wrap .banner .container .navbar {
  margin: 0 15px;
}
#box-wrap .banner .container .navbar .col-nav-l {
  width: 25%;
  float: left;
}
#box-wrap .banner .container .navbar .col-nav-l a {
  width: 52px;
  height: 30px;
  padding: 0;
  font-size: 18px;
  display: block;
}
#box-wrap .banner .container .navbar .col-nav-c {
  width: 75%;
  float: left;
}
#box-wrap .banner .container .navbar .col-nav-c ul {
  display: table;
  margin-bottom: 0;
  padding-left: 0;
  text-align: center;
}
#box-wrap .banner .container .navbar .col-nav-c ul li {
  font-size: 20px;
  display: inline-block;
  position: relative;
  margin-left: 50px;
  float: left;
}
#box-wrap .banner .container .navbar .col-nav-c ul li:first-child a {
  border-bottom: 2px solid #52d3aa;
}
#box-wrap .banner .container .navbar .col-nav-c ul li a {
  color: #000;
  font-weight: 400;
}
#box-wrap .banner .container .navbar .col-nav-c ul li a:hover {
  color: #989898;
}
#box-wrap .intro {
  width: 970px;
  padding-bottom: 5em;
}
#box-wrap .intro .intro-txt {
  width: 60%;
  margin: 0 auto;
}
#box-wrap .intro .intro-txt h2 {
  font-size: 30px;
  line-height: 1.5em;
  margin-bottom: 30px;
  text-align: center;
}

相关文章

  • 2017-3-24 less

    CSS Guards(CSS保护) LESS: Import Directives (导入准则) LESS: CS...

  • web前端学习线路图2

    十二、LESS教程 Less教程Less 安装Less 嵌套规则Less 操作Less 转义Less 函数 Les...

  • Vue项目使用less

    1 先下载less less-loader: npm i less less-loader -S 2 将less配...

  • vue使用less

    npm安装 less less-loader npm install --save less less-loade...

  • Less的使用

    Less使用 1.什么是less 2.less有什么用 3.怎么使用less 4.less批量生成代码 less简...

  • Sql-labs-page3

    less-38 (堆叠注入) 堆叠注入讲解 less-39 解题链接 less-40 less-41 less-...

  • 第十三周第一天笔记之less

    less知识 简书链接less使用总结:less基础知识less使用总结2:less使用总结 单位px,em,re...

  • less的介绍

    less是什么? less是css云处理器 全局安装less包 查看less是否安装成功 less完全兼容css ...

  • LESS/SASS学习记录

    LESS 参考资料:LESS官网w3cplus less入门教程 less的编译 less特性及语法 变量——V...

  • 2017-3-24

    一、学习任务 英语:记背单词 新76 旧100 长难句只看了一个小开头就走了 何凯文每日一句更新 数学:前两章查...

网友评论

      本文标题:2017-3-24 less

      本文链接:https://www.haomeiwen.com/subject/zhqfottx.html