Less – Useful Resources

LESS – Useful Resources ”; Previous Next The following resources contain additional information on Less. Please use them to get more in-depth knowledge on this. Useful Video Courses LESS Online Training 21 Lectures 1 hours Tutorialspoint More Detail Become PHP Facebook Developer: Password-Less Authentication 35 Lectures 4 hours Syed Raza More Detail Getting Started with LESS – Beginner Crash Course 20 Lectures 1.5 hours Sandra L More Detail AWS Glue Studio – A Server less ETL Framework 18 Lectures 58 mins Jim Macaulay More Detail CISA EXAM (Domain 1 in less than an hour) 6 Lectures 35 mins Nokwazi Mtetwa More Detail Microsoft Excel: Become Incredibly Faster less than 2 Hours 25 Lectures 1.5 hours Alexis Bourrachot More Detail Print Page Previous Next Advertisements ”;

Less – Importing

LESS – Importing ”; Previous Next Description It is used to import the contents of the LESS or CSS files. Example The following example demonstrates the use of importing in the LESS file − <html> <head> <title>Less Importing</title> <link rel = “stylesheet” type = “text/css” href = “style.css” /> </head> <body> <h1>Example using Importing</h1> <p class = “myclass”>LESS enables customizable, manageable and reusable style sheet for web site.</p> <p class = “myclass1”>It allows reusing CSS code and writing LESS code with same semantics.</p> <p class = “myclass2”>LESS supports creating cleaner, cross-browser friendly CSS faster and easier.</p> </body> </html> Now create the myfile.less file. myfile.less .myclass { color: #FF8000; } .myclass1 { color: #5882FA; } Now create the style.less file. style.less @import “http://www.tutorialspoint.com/less/myfile.less”; .myclass2 { color: #FF0000; } The myfile.less file which will be imported into style.less from the path https://www.tutorialspoint.com/less/myfile.less You can compile the style.less file to style.css by using the following command − lessc style.less style.css Execute the above command; it will create the style.css file automatically with the following code − style.css .myclass { color: #FF8000; } .myclass1 { color: #5882FA; } .myclass2 { color: #FF0000; } Output Follow these steps to see how the above code works − Save the above html code in the importing.html file. Open this HTML file in a browser, the following output will get displayed. Print Page Previous Next Advertisements ”;

Less – Nested Directives and Bubbling

LESS – Nested Directives and Bubbling ”; Previous Next Description You can nest the directives such as media and keyframe in the same manner, the way you nest the selectors. You can place the directive on top and its relative elements will not be changed inside its rule set. This is known as the bubbling process. Example The following example demonstrates the use of the nested directives and bubbling in the LESS file − <html> <head> <title>Nested Directives</title> <link rel = “stylesheet” type = “text/css” href = “style.css” /> </head> <body> <h1>Example using Nested Directives</h1> <p class = “myclass”>LESS enables customizable, manageable and reusable style sheet for web site.</p> </body> </html> Next, create the file style.less. style.less .myclass { @media screen { color: blue; @media (min-width: 1024px) { color: green; } } @media mytext { color: black; } } You can compile the style.less file to style.css by using the following command − lessc style.less style.css Execute the above command; it will create the style.css file automatically with the following code − style.css @media screen { .myclass { color: blue; } } @media screen and (min-width: 1024px) { .myclass { color: green; } } @media mytext { .myclass { color: black; } } Output Follow these steps to see how the above code works − Save the above html code in the nested_directives_bubbling.html file. Open this HTML file in a browser, the following output will get displayed. Print Page Previous Next Advertisements ”;

Less – Comments

LESS – Comments ”; Previous Next Description Comments make the code clear and understandable for the users. You can use both the block style and the inline comments in the code, but when you compile the LESS code, the single line comments will not appear in the CSS file. Example The following example demonstrates the use of comments in the LESS file − <html> <head> <title>Less Comments</title> <link rel = “stylesheet” type = “text/css” href = “style.css” /> </head> <body> <h1>Example using Comments</h1> <p class = “myclass”>LESS enables customizable, manageable and reusable style sheet for web site.</p> <p class = “myclass1″>It allows reusing CSS code and writing LESS code with same semantics.</p> </body> </html> Now create the style.less file. style.less /* It displays the green color! */ .myclass { color: green; } // It displays the blue color .myclass1 { color: red; } You can compile the style.less file to style.css by using the following command − lessc style.less style.css Now execute the above command; it will create the style.css file automatically with the following code − style.css /* It displays the green color! */ .myclass { color: green; } .myclass1 { color: red; } Output Follow these steps to see how the above code works − Save the above html code in the comments.html file. Open this HTML file in a browser, the following output will get displayed. Print Page Previous Next Advertisements ”;

Less – Nested Rules

LESS – Nested Rules ”; Previous Next Description It is a group of CSS properties which allows using properties of one class into another class and includes the class name as its properties. In LESS, you can declare mixin in the same way as CSS style using class or id selector. It can store multiple values and can be reused in the code whenever necessary. Example The following example demonstrates the use of nested rules in the LESS file − <html> <head> <title>Nested Rules</title> <link rel = “stylesheet” type = “text/css” href = “style.css” /> </head> <body> <div class = “container”> <h1>First Heading</h1> <p>LESS is a dynamic style sheet language that extends the capability of CSS.</p> <div class = “myclass”> <h1>Second Heading</h1> <p>LESS enables customizable, manageable and reusable style sheet for web site.</p> </div> </div> </body> </html> Next, create the style.less file. style.less .container { h1 { font-size: 25px; color:#E45456; } p { font-size: 25px; color:#3C7949; } .myclass { h1 { font-size: 25px; color:#E45456; } p { font-size: 25px; color:#3C7949; } } } You can compile the style.less file to style.css by using the following command − lessc style.less style.css Execute the above command; it will create the style.css file automatically with the following code − style.css .container h1 { font-size: 25px; color: #E45456; } .container p { font-size: 25px; color: #3C7949; } .container .myclass h1 { font-size: 25px; color: #E45456; } .container .myclass p { font-size: 25px; color: #3C7949; } Output Follow these steps to see how the above code works − Save the above html code in the nested_rules.html file. Open this HTML file in a browser, the following output will get displayed. Print Page Previous Next Advertisements ”;

Less – Functions

LESS – Functions ”; Previous Next Description LESS maps JavaScript code with manipulation of values and uses predefined functions to manipulate HTML elements aspects in the style sheet. It provides several functions to manipulate colors such as round function, floor function, ceil function, percentage function etc. Example The following example demonstrates the use of functions in the LESS file − <html> <head> <title>Less Functions</title> <link rel = “stylesheet” type = “text/css” href = “style.css” /> </head> <body> <h1>Example using Functions</h1> <p class = “mycolor”>LESS enables customizable, manageable and reusable style sheet for web site.</p> </body> </html> Now create the style.less file. style.less @color: #FF8000; @width:1.0; .mycolor { color: @color; width: percentage(@width); } You can compile the style.less file to style.css by using the following command − lessc style.less style.css Now execute the above command; it will create the style.css file automatically with the following code − style.css .mycolor { color: #FF8000; width: 100%; } Output Follow these steps to see how the above code works − Save the above html code in the functions.html file. Open this HTML file in a browser, displayed you will receive the following output. Print Page Previous Next Advertisements ”;

Less – Type Functions

LESS – Type Functions ”; Previous Next In this chapter, we will understand the importance of Type Functions in LESS. They are used to determine the type of the value. The following table shows the Type Functions used in LESS. Sr.No. Type Functions & Description Example 1 isnumber It takes a value as parameter and returns true, if it”s a number or false otherwise. isnumber(1234); // true isnumber(24px); // true isnumber(7.8%); // true isnumber(#fff); // false isnumber(red); // false isnumber(“variable”); // false isnumber(keyword); // false isnumber(url(…)); // false 2 isstring It takes a value as parameter and returns true, if it”s a string or false otherwise. isstring(“variable”); // true isstring(1234); // false isstring(24px); // false isstring(7.8%); // false isstring(#fff); // false isstring(red); // false isstring(keyword); // false isstring(url(…)); // false 3 iscolor It takes a value as parameter and returns true, if value is a color or false if it”s not. iscolor(#fff); // true iscolor(red); // true iscolor(1234); // false iscolor(24px); // false iscolor(7.8%); // false iscolor(“variable”); // false iscolor(keyword); // false iscolor(url(…)); // false 4 iskeyword It takes a value as parameter and returns true, if value is a keyword or false if it”s not. iskeyword(keyword); // true iskeyword(1234); // false iskeyword(24px); // false iskeyword(7.8%); // false iskeyword(#fff); // false iskeyword(red) ; // false iskeyword(“variable”);// false iskeyword(url(…)); // false 5 isurl It takes a value as parameter and returns true, if value is a url or false if it”s not. isurl(url(…)); // true isurl(keyword); // false isurl(1234); // false isurl(24px); // false isurl(7.8%); // false isurl(#fff); // false isurl(red) ; // false isurl(“variable”); // false 6 ispixel It takes a value as parameter and returns true, if value is a number in pixels or false otherwise. ispixel(24px); // true ispixel(1234); // false ispixel(7.8%); // false ispixel(keyword); // false ispixel(#fff); // false ispixel(red) ; // false ispixel(“variable”); // false ispixel(url(…)); // false 7 isem It takes a value as parameter and returns true, if value is an em value or false if it”s not. isem(0.5em); // true isem(1234); // false isem(24px); // false isem(keyword); // false isem(#fff); // false isem(red) ; // false isem(“variable”); // false isem(url(…)); // false 8 ispercentage It takes a value as parameter and returns true, if value is in percentage or returns false, if value is not in percentage. ispercentage(7.5%); // true ispercentage(url(…)); // false ispercentage(keyword); // false ispercentage(1234); // false ispercentage(24px); // false ispercentage(#fff); // false ispercentage(red) ; // false ispercentage(“variable”); // false 9 isunit It returns true if a value is a number in specified units provided as parameter or it will return false if value is not a number in specified units. isunit(10px, px); // true isunit(5rem, rem); // true isunit(7.8%, ”%”); // true isunit(2.2%, px); // false isunit(24px, rem); // false isunit(48px, “%”); // false isunit(1234, em); // false isunit(#fff, pt); // false isunit(“mm”, mm); // false 10 isruleset It takes a value as parameter and returns true, if value is a ruleset or false otherwise. @rules: { color: green; } isruleset(@rules); // true isruleset(1234); // false isruleset(24px); // false isruleset(7.8%); // false isruleset(#fff); // false isruleset(blue); // false isruleset(“variable”); // false isruleset(keyword); // false isruleset(url(…)); // false Print Page Previous Next Advertisements ”;

Less – Color Blending Functions

LESS – Color Blending Functions ”; Previous Next In this chapter, we will understand the Color Blending Functions in LESS. These are similar operations used in image editors like Photoshop, Fireworks or GIMP, which matches your CSS colors to your images. The following table shows the color blending functions used in LESS. Sr.No. Functions & Description 1 multiply It multiplies two colors and returns a resultant color. 2 screen It takes two colors and returns a brighter color. It works opposite of multiply function. 3 overlay It generates result by combining the effect of multiply and screen. 4 softlight It works similar to overlay but it uses only a part of the color, which soft-highlights the other color. 5 hardlight It works similar to overlay but the role of the colors reversed. 6 difference It subtracts the second input color from the first input color. 7 exclusion It works similar to difference function but with lower contrast. 8 average It computes the average of two input colors on a per-channel (RGB) basis. 9 negation It works opposite to difference function, which subtracts first color from second color. Print Page Previous Next Advertisements ”;

Less – Mixins

LESS – Mixins ”; Previous Next Mixins are similar to functions in programming languages. Mixins are a group of CSS properties that allow you to use properties of one class for another class and includes class name as its properties. In LESS, you can declare a mixin in the same way as CSS style using class or id selector. It can store multiple values and can be reused in the code whenever necessary. The following table demonstrates the use of LESS mixins in detail. Sr.No. Mixins usage & Description 1 Not Outputting the Mixin Mixins can be made to disappear in the output by simply placing the parentheses after it. 2 Selectors in Mixins The mixins can contain not just properties, but they can contain selectors too. 3 Namespaces Namespaces are used to group the mixins under a common name. 4 Guarded Namespaces When guard is applied to namespace, mixins defined by it are used only when the guard condition returns true. 5 The !important keyword The !important keyword is used to override the particular property. Example The following example demonstrates the use of mixins in the LESS file − <html> <head> <link rel = “stylesheet” href = “style.css” type = “text/css” /> <title>LESS Mixins</title> </head> <body> <h1>Welcome to Tutorialspoint</h1> <p class = “p1”>LESS is a CSS pre-processor that enables customizable, manageable and reusable style sheet for web site.</p> <p class = “p2”>LESS is a dynamic style sheet language that extends the capability of CSS.</p> <p class = “p3″>LESS is cross browser friendly.</p> </body> </html> Next, create the style.less file. style.less .p1 { color:red; } .p2 { background : #64d9c0; .p1(); } .p3 { background : #LESS520; .p1; } You can compile the style.less to style.css by using the following command − lessc style.less style.css Execute the above command; it will create the style.css file automatically with the following code − style.css .p1 { color: red; } .p2 { background: #64d9c0; color: red; } .p3 { background: #LESS520; color: red; } Output Follow these steps to see how the above code works − Save the above html code in the less_mixins.html file. Open this HTML file in a browser, the following output will get displayed. The parentheses are optional when calling mixins. In the above example, both statements .p1(); and .p1; do the same thing. Print Page Previous Next Advertisements ”;

Less – Installation

LESS – Installation ”; Previous Next In this chapter, we will understand, in a step-by-step manner, how to install LESS. System Requirements for LESS Operating System − Cross-platform Browser Support − IE (Internet Explorer 8+), Firefox, Google Chrome, Safari. Installation of LESS Let us now understand the installation of LESS. Step 1 − We need NodeJs to run LESS examples. To download NodeJs, open the link https://nodejs.org/en/, you will see a screen as shown below − Dowload the Latest Features version of the zip file. Step 2 − Run the setup to install the Node.js on your system. Step 3 − Next, Install LESS on the server via NPM (Node Package Manager). Run the following command in the command prompt. npm install -g less Step 4 − After successful installation of LESS, you will see the following lines on the command prompt − `– [email protected] +– [email protected] | `– [email protected] +– [email protected] +– [email protected] +– [email protected] +– [email protected] | `– [email protected] +– [email protected] | `– [email protected] +– [email protected] | +– [email protected] | +– [email protected] | | `– [email protected] | | +– [email protected] | | `– [email protected] | +– [email protected] | | `– [email protected] | | +– [email protected] | | +– [email protected] | | +– [email protected] | | +– [email protected] | | +– [email protected] | | `– [email protected] | +– [email protected] | +– [email protected] | | `– [email protected] | +– [email protected] | +– [email protected] | +– [email protected] | | `– [email protected] | +– [email protected] | | +– [email protected] | | | +– [email protected] | | | | `– [email protected] | | | +– [email protected] | | | +– [email protected] | | | | `– [email protected] | | | +– [email protected] | | | `– [email protected] | | +– [email protected] | | | `– [email protected] | | +– [email protected] | | | +– [email protected] | | | +– [email protected] | | | | `– [email protected] | | | +– [email protected] | | | `– [email protected] | | `– [email protected] | | `– [email protected] | +– [email protected] | | +– [email protected] | | +– [email protected] | | +– [email protected] | | `– [email protected] | +– [email protected] | | +– [email protected] | | +– [email protected] | | | +– [email protected] | | | +– [email protected] | | | `– [email protected] | | `– [email protected] | | +– [email protected] | | +– [email protected] | | | `– [email protected] | | +– [email protected] | | +– [email protected] | | +– [email protected] | | `– [email protected] | +– [email protected] | +– [email protected] | +– [email protected] | +– [email protected] | | `– [email protected] | +– [email protected] | +– [email protected] | +– [email protected] | +– [email protected] | +– [email protected] | `– [email protected] `– [email protected] Example Following is a simple example of LESS. hello.htm <!doctype html> <head> <link rel = “stylesheet” href = “style.css” type = “text/css” /> </head> <body> <h1>Welcome to TutorialsPoint</h1> <h3>Hello!!!!!</h3> </body> </html> Let us now create a file style.less which is quite similar to CSS, the only difference is that it will be saved with .less extension. Both the files, .html and .less should be created inside the folder nodejs. style.less @primarycolor: #FF7F50; @color:#800080; h1 { color: @primarycolor; } h3 { color: @color; } Compile style.less file to style.css by using the following command − lessc style.less style.css When you run the above command, it will create the style.css file automatically. Whenever you change the LESS file, it”s necessary to run the above command in the cmd and then the style.css file will get updated. The style.css file will have the following code when you run the above command − style.css h1 { color: #FF7F50; } h3 { color: #800080; } Output Let us now carry out the following steps to see how the above code works − Save the above html code in the hello.htm file. Open this HTML file in a browser, the following output will get displayed. Print Page Previous Next Advertisements ”;