What is less?

Source: Internet
Author: User

What is less?

Simply put, you can use variables, functions, and so on in your CSS file to write your CSS.

What are the features of less?
    • Mix the class in the (mixins)--class;
    • parameters are mixed --the class that can pass the parameter, just like a function;
    • Nested rules are nested in the--class class, thus reducing duplication of code;
    • Mathematics is used in the arithmetic --css;
    • Color Function --can edit color;
    • Namespaces (namespace)--grouping styles, which can be called;
    • Scope -local modification style;
    • JavaScript Assignment --use JavaScript expressions to assign values in CSS.
How do I use less in your project?


1. Download Less.js first.
2. Create your less file, such as Index.less.
3. Introduction of the above 2 files in your

Rel= "stylesheet/less" type= "Text/css" href= "css/index.less"/>

There are 2 points to note here: First, the rel attribute of the link tag must be ' stylesheet/less ', and the second is that less.js must be introduced after index.less.
Now you can officially experience less.

1. Nesting

Nesting and writing CSS like nested HTML

. Wrap{background: @gray;p adding:30px;h1{font:18px/2 ' Microsoft Yahei '}}

2. Mixing

No need to add more than one class to the HTML, just do it in CSS

. Box2{.wrap}

3. Parameter mixing

Like JS function can pass parameters, no need to write CSS repeatedly

1. For example, a fillet effect that requires CSS3 first defines a class, the fillet value is passed in as a parameter, and the default value of 5px is set:
. Border (@a:5px) {-webkit-border-radius:@a;-moz-border-radius:@a;border-radius:@a;}

2. Use:. Box3{.border (20px)}

4. Selector inheritance

I feel this function is a little bit like mixing, not much use

5. Operations

This is more practical, using numbers or variables to perform operations

@base_margin: 10px;

@double_margin: @base_margin * 2;

Use:. Box5{.border (10px); border: @base_width/2 Solid #ccc}

6.color function

Lighten function: Reduce the color by a percentage; less also provides additional dimming or adjustment of the color saturation function

Lighten (@gray, 10%), actually displays only @gray 90% of the color

What is less?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.