Compile CSS into LESS


Compile LESS: It's CSS, with just a little more.

Less (which stands for Leaner Style Sheets) is a backwards-compatible language extension for CSS. Because Less looks just like CSS, learning it is a breeze. Less only makes a few convenient additions to the CSS language, which is one of the reasons it can be learned so quickly.

This is a free tool and does the job in a few seconds so you don't have to do it manually. Feel free to use this tool for your css less code and easily extend your CSS to support Less's additional features and benefits.

Why use LESS? What does Less add to CSS?

Here's a quick overview of the features and functionality that LESS adds to your CSS code:

Variables

Less allows variables to be defined which is very useful and helpful in keeping track of your colors and other styles in CSS. Variables in Less are defined with an at sign (@). Variable assignment is done with a colon (:).During translation, the values of the variables are inserted into the output CSS document.

    @pale-green-color: #4D926F;

    #header {
    color: @pale-green-color;
    }
    h2 {
    color: @pale-green-color;
    }

The code above in Less would compile to the following CSS code.

    #header {
    color: #4D926F;
    }
    h2 {
    color: #4D926F;
    }

Mixins

Mixins allow embedding all the properties of a class into another class by including the class name as one of its properties, thus behaving as a sort of constant or variable. They can also behave like functions, and take arguments. CSS does not support Mixins: Any repeated code must be repeated in each location. Mixins allow for more efficient and clean code repetitions, as well as easier alteration of code.

    .rounded-corners (@radius: 5px 10px 8px 2px) {
    -webkit-border-radius: @radius;
    -moz-border-radius: @radius;
    border-radius: @radius;
    }

    #header {
    .rounded-corners;
    }
    #footer {
    .rounded-corners(10px 25px 35px 0px);
    }

The above code in Less would compile to the following CSS code:

    #header {
    -webkit-border-radius: 5px 10px 8px 2px;
    -moz-border-radius: 5px 10px 8px 2px;
    border-radius: 5px 10px 8px 2px;
    }
    #footer {
    -webkit-border-radius: 10px 25px 35px 0px;
    -moz-border-radius: 10px 25px 35px 0px;
    border-radius: 10px 25px 35px 0px;
    }

Less has a special type of ruleset called parametric mixins which can be mixed in like classes, but accepts parameters.

    #header {
    h1 {
    font-size: 26px;
    font-weight: bold;
    }
    p {
    font-size: 16px;
    a {
    text-decoration: none;
    color: red;
    &:hover {
    border-width: 1px;
    color: #fff;
    }
    }
    }
    }
    

The above code in Less would compile to the following CSS code:

    #header h1 {
    font-size: 26px;
    font-weight: bold;
    }
    #header p {
    font-size: 16px;
    }
    #header p a {
    text-decoration: none;
    color: red;
    }
    #header p a:hover {
    border-width: 1px;
    color: #fff;
    }

Functions and operations

Less allows operations and functions. Operations allow addition, subtraction, division and multiplication of property values and colors, which can be used to create complex relationships between properties. Functions map one-to-one with JavaScript code, allowing manipulation of values.

    @the-border: 1px;
    @base-color: #111;
    @red:        #842210;

    #header {
    color: @base-color * 3;
    border-left: @the-border;
    border-right: @the-border * 3;
    }
    #footer {
    color: @base-color + #003300;
    border-color: desaturate(@red, 10%);
    }
    The above code in Less would compile to the following CSS code:

    #header {
    color: #333333;
    border-left: 1px;
    border-right: 3px;
    }
    #footer {
    color: #114411;
    border-color: #7d2717;
    }
    

External Links


© 2018 CSS Minifier | Privacy Policy | 3 Reasons to Minimize your CSS | Sitemap