less 初探

官方文档 

## Less 中文网 http://lesscss.cn/

## Less 官网 http://lesscss.org/


使用

1.  Use with Node.js:

npm install -g less

lessc styles.less styles.css 

2. browser:

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

<script src="//cdnjs.cloudflare.com/ajax/libs/less.js/3.7.1/less.min.js" ></script>


主要(常用):

变量(Variables)

混合(Mixins)

嵌套(Nesting)

运算(Operations)

导入(Importing)

作用域(Scope)

Maps

Escaping

注释(Comments)
插件:npm install less-plugin-clean-css

//cdnjs.cloudflare.com/ajax/libs/less.js/3.7.1/less.min.js" >


index.html

<!doctype html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <title>初识 Less</title>

    <style>

        @import "./main.min.css"

    </style>

    <!-- <link href="./main.min.css" rel="stylesheet"> -->

</head>

<body>

    <div class="container">1</div>

    <div class="container2">

        2

        <span>haha</span>

    </div>

    <div class="container3">3</div>

    <div class="naim">

        Lorem ipsum dolor sit amet, consectetur adipisicing elit.

        Ex aspernatur nobis ipsa quia neque ad corporis deleniti,

        necessitatibus quam voluptatem est rerum numquam doloribus!

        Quo ducimus aperiam accusamus velit sequi!

    </div>

</body>

</html>


main.less

@width: 100%;

@height: 100%;

@color: red;

@white: #fff;

@borderH: 1px;

@left: 15px;

@max768: ~"(max-width: 768px)";

@min320: ~"(min-width: 320px)";

.border-radius (@radius:4px) {

    -moz-border-radius: @radius;

    -webkit-border-radius: @radius;

}

.bordered {

    border-top: dotted 10px black;

    border-bottom: solid 2px black;

}

.container{

    color: @white;

    width: @width;

    height: @height;

    background: @color;

    margin-bottom: 15px;

    .bordered();

}

.container2{

    width: @width;

    height: @height;

    background: @white;

    margin-bottom: 5px;

    span {

        font-size: 24px;

        color: @color;


        &:before {

            content: '';

            display: inline-block;

            width: 6px;

            height: 20px;

            margin-right: @left;

            background: yellow;

        }

        @media @max768 {

            color: blue;

        }

        @media @min320 {

            color: yellow;

        }

    }

    border-top: @borderH+2 solid black;

}

.container3{

    width: @width;

    height: @height;

    background-color: @color;

    margin-bottom: 5px;

    border: 1px solid @color;

    .border-radius(10px);

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 各种纯css图标 CSS3可以实现很多漂亮的图形,我收集了32种图形,在下面列出。直接用CSS3画出这些图形,要比...
    剑残阅读 9,676评论 0 8
  • 5.椭圆 #ellipse{ width: 200px; height: 100px; background-co...
    小茶叶叶阅读 2,123评论 0 1
  • 1. tab列表折叠效果 html: 能源系统事业部 岗位名称: 工作地点 岗位名...
    lilyping阅读 1,897评论 0 1
  • "你要带我去哪?"舒迪雅拉着方晓因的手,快步向前走去。 "等下就知道了。"舒迪雅抿着嘴唇说。 舒迪雅把方晓因拉到潮...
    初肆阅读 386评论 0 2
  • 二月抬起了眉眼 为即将上演的 新的芽儿,开的香,舞的蝶 筹备着舞台 她把腊月偷走的阳光还给了 已冻僵的江河 又用自...
    枝上铃铛阅读 396评论 38 49