Inner div should be green.
In the style.less file , add the following lines:
@bg-color: red; body { font-size: 40px; color: white; margin: 20px; } .inner-div { @bg-color: green; background-color: @bg-color; } .outer-div { background-color: @bg-color; }
The inner-div block redefines the bg-color variable, which resides only within that block. Therefore, the green color only applies to that class and does not affect the global bg-color variable. When you compile and open the results in a browser, you'll see:
Less also provides handy functions that can be useful in some situations. For example, if you want to set a style only when a specific condition is met, you can do that using the if function. This function has the following syntax:
if((condition), value1, value2)
This code returns value1 if the condition is met, otherwise it returns value2 . For example:
@var1: 20px; @var2: 20px; div { padding: if((@var1 = @var2), 10px, 20px); }
The above code block will result in CSS after it is compiled:
div { padding: 10px; }
Features like functions, mixins, and variables are just a small part of what Less has to offer. Less is suitable for both small and large projects. Try and feel for yourself the wonderful things that Less brings to CSS.