Less.js Extend Duplication Detection
Last Updated :
23 Oct, 2022
LESS is a simple CSS pre-processor that makes it possible to create manageable, customizable, and reusable style sheets for websites. LESS is a dynamic style sheet language that increases the working power of CSS. LESS is cross-browser compatible. CSS pre-processor is a scripting language that improves CSS and gets compiled into regular CSS syntax so that the web browser can use it. This also provides functionalities like variables, functions, mixins, and operations that enable us to build dynamic CSS.
Extend: LESS Extend is a pseudo-class that helps to merge different selectors, based on putting it with one that matches according to what it is referenced. We can use the LESS extend feature using the : extend keyword.
Duplication Detection: Duplication Detection cannot detect the duplication of selectors. Currently, there is no duplication detection.
Parameter: We can use the LESS extend feature using the :extend keyword.
Syntax:
.hello-world,
.style {
...
}
Example 1: The following example demonstrates the use of duplication detection in the LESS file.
HTML
<!doctype html>
< head >
< link rel = "stylesheet" href = "style.css"
type = "text/css" />
</ head >
< body >
< div class = "hello-world" >
< h1 >GeeksforGeeks</ h1 >
< div class = "style" >
< ul >
< li >Anuj </ li >
< li >AADI</ li >
< li >Sattu</ li >
< li >Balit</ li >
< li >Sonu</ li >
</ ul >
</ div >
</ div >
</ body >
</ html >
|
style. less
CSS
@ color : green ;
@rd: red ;
.hello-world,
.style {
font-family : "Comic Sans MS" ;
font-size : 30px ;
color : @rd;
}
.hello-world {
font-size : 30px ;
}
.hello:extend(.hello-world, .style) {}
h 1 {
color : @color;
}
|
Now, to compile the above LESS code to CSS code, run the following command:
lessc style.less style.css
The compiled CSS file comes to be:
CSS
.hello-world,
.style,
.hello,
.hello {
font-family : "Comic Sans MS" ;
font-size : 30px ;
color : red ;
}
.hello-world,
.hello {
font-size : 30px ;
}
h 1 {
color : green ;
}
|
Output:
Example 2: The following example demonstrates the use of duplication detection in the LESS file.
HTML
<!DOCTYPE html>
< head >
< title >Merge Space Example</ title >
< link rel = "stylesheet" href = "style.css"
type = "text/css" />
</ head >
< body >
< div class = "alert-info" >
< h1 >GeeksforGeeks</ h1 >
< a >Duplication detection</ a >
</ div >
</ body >
</ html >
|
style. less:
CSS
.alert-info,
.widget {
border : 4px dashed blue ;
width : 210px ;
height : 70px ;
color : green ;
text-align : center ;
}
.alert:extend(.alert-info, .widget) {}
a {
color : red ;
background-color : black ;
text-align : center ;
}
|
Now, to compile the above LESS code to CSS code, run the following command:
lessc style.less style.css
The compiled CSS file comes to be:
style.css
CSS
.alert-info,
.widget,
.alert,
.alert {
border : 4px dashed blue ;
width : 210px ;
height : 70px ;
color : green ;
text-align : center ;
}
a {
color : red ;
background-color : black ;
text-align : center ;
}
|
Output:
Reference: https://lesscss.org/features/#extend-feature-duplication-detection
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...