What Is LESS?
LESS is a dynamic stylesheet language which gives you more options and freedom when writing CSS. It helps you keep styles better organized, cascade styles more naturally and correct, and it speeds up CSS development in general. Also it’s a simple language which can be learned in a matter of hours by anyone with some programming experience. Even if you don’t have programming skills, it won’t take you long to learn at least its basic features.
LESS Dynamic Stylesheet Language
LESS syntax
The idea with LESS is to help you develop faster, not to put an additional burden on your shoulders. It can be a lifesaver in large projects such GroupDocs. Described as simply as possible, you write CSS pretty much the same way you’ve always done using the CSS syntax, but with a different mindset when you’re writing in LESS. Which means that you now have options which allow you to write less code. LESS’ slogan is “LESS is more”. Let’s write a few CSS styles and see how we can improve them with less syntax:.blog-article {
height: 300px;
}
.blog-article .image {
display: block;
float: left;
border: 3px dashed black;
}
.blog-article h2 {
font-size: 24px;
color: #ccc;
text-shadow: 1px 1px #000;
}.blog-article {
height: 300px;
.image {
display: block;
float: left;
border: 3px dashed black;
}
h2 {
font-size: 24px;
color: #ccc;
text-shadow: 1px 1px #000;
}
}.blog-article {
height: 300px;
&.longer {
height: 500px;
}
}.blog-article {
height: 300px;
}
.blog-article.longer {
height: 500px;
}Variables
As in classical programming languages, variables are used as containers where you store information as number values or text, depending on your needs. You can find a whole file in Bootstrap filled only with variables so developers can easily change different styles for their projects such as text colors or font types:@gray: #555; @sansFontFamily: "PT Sans", Helvetica, Arial, sans-serif;
.blog-article {
h2 {
font-family: @sansFontFamily;
font-size: @fontLarge;
color: @gray;
}
}h4 {
font-size: @fontLarge / 2;
}Mixins
Mixins are great for reusing code, something which is a big issue in CSS development. For example, imagine that you have multiple elements with blue background and some image pattern. You can make a simple ruleset that has these background styles inside it and reuse it where you need it later on:// This is a simple CSS ruleset which can be added as a mixin inside other rulesets to inherit its properties
.blue-background {
background: @blue url(path/img.png) 0 0 repeat-x;
}
.blog-article {
.blue-background;
}
.widget-box {
color: @white;
border: 2px solid @lime;
.blue-background;
}
// The code above compiles into:
.blog-article {
background: #049cdb url(path/img.png) 0 0 repeat-x;
}
.widget-box {
color: #fff;
border: 2px solid #83ff46;
background: #049cdb url(path/img.png) 0 0 repeat-x;
}.border-radius (@radius) {
border-radius: @radius;
-moz-border-radius: @radius;
-webkit-border-radius: @radius;
}.button {
.border-radius(5px);
}
// This outputs to the following CSS
.button {
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
}

