SlideShare ist ein Scribd-Unternehmen logo
1 von 21
Ankit Shukla
Knoldus Software LLP
Ankit Shukla
Knoldus Software LLP
Less
Topics to be Covered
● About Less
● Variables
● Scope
● Mixins
● Nested Rules
● Namespaces
● Operations
● Functions
● Extend
● Mixin Guards
● Loop
● Parent Selector
About Less
● Less is a CSS pre-processor, meaning that it extends the CSS language, adding
features that allow variables, mixins, functions and many other techniques.
● Developed by Alexis Sellier in 2009.
● The current stable version is 1.7.3
● Inspired by SASS.
●
Variables
● Variables in less are defined with @
● The assignment is done by :
● It stores a constant value.
● Some properties are used many times in our CSS.
It helps to make our code easier to maintain by
giving us way to control the repeated properties
from a single location.
Variables Continues...
Less Code:
@color : #33333;
p{
color : @color;
}
.demo {
background : @color;
}
Output :
p{
color : #333333;
}
.demo{
background : #333333;
}
Scope
@var: red;
#page {
#header {
@var: white;
color: @var; // white
}
color : @var;
}
● Output
#page {
color: #ff0000;
}
#page #header {
color: #ffffff;
}
Mixin
.demo-class{
color : #aaa;
font-size : 20px;
}
.class-A{
.demo-class;
background : #000;
}
Output:
.demo-class {
color: #aaa;
font-size: 20px;
}
.class-A{
color : #aaa;
font-size : 20px;
background : #000;
}
If you do not want that mixin to be output, you can put
parenthesis after it.
.mixin {
color: black;
}
.other-mixin() {
background: white;
}
.class {
.my-mixin;
.other-mixin;
}
Output:
.mixin {
color: black;
}
.class {
color: black;
background: white;
}
Parametric Mixins
.demo-class(@padding){
padding : @padding;
}
.class-A{
.demo-class(5px);
background : #000;
}
.class-B{
.demo-class(8px);
}
Output
.class-A{
padding : 5px;
background : #000;
}
.class-B{
padding : 8px;
}
Nested Rules
#header {
color: #999;
.logo {
width: 300px;
&:hover{
width:350px;
}
}
}
Output:
#header {
color: #999;
}
#header .logo {
width: 300px;
}
#header .logo:hover {
width: 350px;
}
Namespaces
#bundle {
.button {
display: block;
border: 1px solid black;
background-color: grey;
}
}
#header a {
color: orange;
#bundle > .button;
}
● Output
#bundle .button {
display: block;
border: 1px solid black;
background-color: grey;
}
#header a {
color: orange;
display: block;
border: 1px solid black;
background-color: grey;
}
Operations
@base: 5%;
@filler: @base * 2;
@other: @base + @filler;
@base-color : #aaa;
#class{
color: #888 / 4;
background-color: @base-color + #111;
height: 100% / 2 + @filler;
width : @other + 50%;
}
● Output
#class {
color: #222222;
background-color: #bbbbbb;
height: 60%;
width: 65%;
}
Functions
@base: #f04615;
@width: 0.5;
.class {
width: percentage(@width);
color: saturate(@base, 5%);
}
● Output
.class {
width: 50%;
color: #f6430f;
}
Extend
● Extend is a Less Pseudo-Class which merges the
selector it is put on with ones that match what it
references.
● Extend Syntax : .a:extend(.b) {} or
.a { &:extend(.b);}
Extend Continues...
.a {
color : #666;
}
.b:extend(.a){
font-size : 24px ;
}
● Output
.a,
.b {
color: #666;
}
.b {
font-size: 24px ;
}
Extend All
.test.c {
color: orange;
}
.test {
color : #555;
}
.replacement {
&:extend(.test all);
}
● Output
.test.c,
.replacement.c {
color: orange;
}
.test,
.replacement {
color: #555;
}
Mixin Gaurds
.mixin (@a) when (percentage(@a) >=
50%) {
background-color: black;
}
.mixin (@a) when (percentage(@a) < 50%)
{
background-color: white;
}
.mixin (@a) {
width: percentage(@a);
}
.class1 { .mixin(.4) }
.class2 { .mixin(.6) }
● Output
.class1 {
background-color: white;
width: 40%;
}
.class2 {
background-color: black;
width: 60%;
}
Loop
.generate-columns(@n, @i: 1) when
(@i =< @n) {
.column-@{i} {
width: (@i * 100% / @n);
}
.generate-columns(@n, (@i + 1));
}
.generate-columns(2);
● Output
.column-1 {
width: 50%;
}
.column-2 {
width: 100%;
}
Parent Selector
.A {
.B {
&:hover{
color :#222;
}
& & {
color: green;
}
}
}
● Output
.A .B:hover {
color: #222;
}
.A .B .A .B {
color: green;
}
Parent Selector Continues...
.header {
.menu {
border-radius: 5px;
.no-borderradius & {
border : none;
}
}
}
● Output
.header .menu {
border-radius: 5px;
}
.no-borderradius .header .menu {
border: none;
}
Thank You :)

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Workshop 18: CSS Animations & cool effects
Workshop 18: CSS Animations & cool effectsWorkshop 18: CSS Animations & cool effects
Workshop 18: CSS Animations & cool effects
 
Web Design Course: CSS lecture 2
Web Design Course: CSS  lecture 2Web Design Course: CSS  lecture 2
Web Design Course: CSS lecture 2
 
Workshop 6: Designer tools
Workshop 6: Designer toolsWorkshop 6: Designer tools
Workshop 6: Designer tools
 
Web Design Course: CSS lecture 3
Web Design Course: CSS lecture 3Web Design Course: CSS lecture 3
Web Design Course: CSS lecture 3
 
Css web side
Css web sideCss web side
Css web side
 
Accelerated Stylesheets
Accelerated StylesheetsAccelerated Stylesheets
Accelerated Stylesheets
 
Web Design Course: CSS lecture 4
Web Design Course: CSS  lecture 4Web Design Course: CSS  lecture 4
Web Design Course: CSS lecture 4
 
Taming CSS Selectors
Taming CSS SelectorsTaming CSS Selectors
Taming CSS Selectors
 
Web Engineering - Basic CSS Properties
Web Engineering - Basic CSS PropertiesWeb Engineering - Basic CSS Properties
Web Engineering - Basic CSS Properties
 
Ruby On Rails
Ruby On RailsRuby On Rails
Ruby On Rails
 
Getting started with css
Getting started with cssGetting started with css
Getting started with css
 
Pemrograman Web 3 - CSS Basic Part 2
Pemrograman Web 3 - CSS Basic Part 2Pemrograman Web 3 - CSS Basic Part 2
Pemrograman Web 3 - CSS Basic Part 2
 
Web Design Course: CSS lecture 1
Web Design Course: CSS lecture 1Web Design Course: CSS lecture 1
Web Design Course: CSS lecture 1
 
CSS Walktrough Internship Course
CSS Walktrough Internship CourseCSS Walktrough Internship Course
CSS Walktrough Internship Course
 
Jekyll - Liquid for noobs
Jekyll - Liquid for noobsJekyll - Liquid for noobs
Jekyll - Liquid for noobs
 
Compile your Style
Compile your StyleCompile your Style
Compile your Style
 
CSS3 Refresher
CSS3 RefresherCSS3 Refresher
CSS3 Refresher
 
Forms and Databases in PHP
Forms and Databases in PHPForms and Databases in PHP
Forms and Databases in PHP
 
Landing Pages 101
Landing Pages 101Landing Pages 101
Landing Pages 101
 
My 70-480 HTML5 certification learning
My 70-480 HTML5 certification learningMy 70-480 HTML5 certification learning
My 70-480 HTML5 certification learning
 

Andere mochten auch (6)

GulpJs - An Introduction
GulpJs - An IntroductionGulpJs - An Introduction
GulpJs - An Introduction
 
Scala oo
Scala ooScala oo
Scala oo
 
Scala idioms
Scala idiomsScala idioms
Scala idioms
 
Backbone js
Backbone jsBackbone js
Backbone js
 
Scala parallel-collections
Scala parallel-collectionsScala parallel-collections
Scala parallel-collections
 
Backbonejs
BackbonejsBackbonejs
Backbonejs
 

Ähnlich wie Introduction To Less

LeSS in action
LeSS in actionLeSS in action
LeSS in action
Pu Shiming
 
Software programming tools for creating/managing CSS files
Software programming tools for creating/managing CSS filesSoftware programming tools for creating/managing CSS files
Software programming tools for creating/managing CSS files
Dinu Suman
 
LESS is More
LESS is MoreLESS is More
LESS is More
jsmith92
 
Coder Presentation Boston
Coder Presentation BostonCoder Presentation Boston
Coder Presentation Boston
Doug Green
 

Ähnlich wie Introduction To Less (20)

LeSS in action
LeSS in actionLeSS in action
LeSS in action
 
Doing more with LESS
Doing more with LESSDoing more with LESS
Doing more with LESS
 
Doing More With Less
Doing More With LessDoing More With Less
Doing More With Less
 
Software programming tools for creating/managing CSS files
Software programming tools for creating/managing CSS filesSoftware programming tools for creating/managing CSS files
Software programming tools for creating/managing CSS files
 
Degrafa Top 5 Features
Degrafa Top 5 FeaturesDegrafa Top 5 Features
Degrafa Top 5 Features
 
Agile CSS development with Compass and Sass
Agile CSS development with Compass and SassAgile CSS development with Compass and Sass
Agile CSS development with Compass and Sass
 
LESS is More
LESS is MoreLESS is More
LESS is More
 
UI Realigning & Refactoring by Jina Bolton
UI Realigning & Refactoring by Jina BoltonUI Realigning & Refactoring by Jina Bolton
UI Realigning & Refactoring by Jina Bolton
 
Coder Presentation Boston
Coder Presentation BostonCoder Presentation Boston
Coder Presentation Boston
 
Write LESS. DO more.
Write LESS. DO more.Write LESS. DO more.
Write LESS. DO more.
 
CSS3
CSS3CSS3
CSS3
 
Php
PhpPhp
Php
 
End-to-End SPA Development using TypeScript
End-to-End SPA Development using TypeScriptEnd-to-End SPA Development using TypeScript
End-to-End SPA Development using TypeScript
 
"Xapi-lang For declarative code generation" By James Nelson
"Xapi-lang For declarative code generation" By James Nelson"Xapi-lang For declarative code generation" By James Nelson
"Xapi-lang For declarative code generation" By James Nelson
 
PHP BASIC PRESENTATION
PHP BASIC PRESENTATIONPHP BASIC PRESENTATION
PHP BASIC PRESENTATION
 
Linux Shell Scripting Craftsmanship
Linux Shell Scripting CraftsmanshipLinux Shell Scripting Craftsmanship
Linux Shell Scripting Craftsmanship
 
Intro to React
Intro to ReactIntro to React
Intro to React
 
Oops lecture 1
Oops lecture 1Oops lecture 1
Oops lecture 1
 
Building End to-End Web Apps Using TypeScript
Building End to-End Web Apps Using TypeScriptBuilding End to-End Web Apps Using TypeScript
Building End to-End Web Apps Using TypeScript
 
Sass Essentials
Sass EssentialsSass Essentials
Sass Essentials
 

Mehr von Knoldus Inc.

Mehr von Knoldus Inc. (20)

Supply chain security with Kubeclarity.pptx
Supply chain security with Kubeclarity.pptxSupply chain security with Kubeclarity.pptx
Supply chain security with Kubeclarity.pptx
 
Mastering Web Scraping with JSoup Unlocking the Secrets of HTML Parsing
Mastering Web Scraping with JSoup Unlocking the Secrets of HTML ParsingMastering Web Scraping with JSoup Unlocking the Secrets of HTML Parsing
Mastering Web Scraping with JSoup Unlocking the Secrets of HTML Parsing
 
Akka gRPC Essentials A Hands-On Introduction
Akka gRPC Essentials A Hands-On IntroductionAkka gRPC Essentials A Hands-On Introduction
Akka gRPC Essentials A Hands-On Introduction
 
Entity Core with Core Microservices.pptx
Entity Core with Core Microservices.pptxEntity Core with Core Microservices.pptx
Entity Core with Core Microservices.pptx
 
Introduction to Redis and its features.pptx
Introduction to Redis and its features.pptxIntroduction to Redis and its features.pptx
Introduction to Redis and its features.pptx
 
GraphQL with .NET Core Microservices.pdf
GraphQL with .NET Core Microservices.pdfGraphQL with .NET Core Microservices.pdf
GraphQL with .NET Core Microservices.pdf
 
NuGet Packages Presentation (DoT NeT).pptx
NuGet Packages Presentation (DoT NeT).pptxNuGet Packages Presentation (DoT NeT).pptx
NuGet Packages Presentation (DoT NeT).pptx
 
Data Quality in Test Automation Navigating the Path to Reliable Testing
Data Quality in Test Automation Navigating the Path to Reliable TestingData Quality in Test Automation Navigating the Path to Reliable Testing
Data Quality in Test Automation Navigating the Path to Reliable Testing
 
K8sGPTThe AI​ way to diagnose Kubernetes
K8sGPTThe AI​ way to diagnose KubernetesK8sGPTThe AI​ way to diagnose Kubernetes
K8sGPTThe AI​ way to diagnose Kubernetes
 
Introduction to Circle Ci Presentation.pptx
Introduction to Circle Ci Presentation.pptxIntroduction to Circle Ci Presentation.pptx
Introduction to Circle Ci Presentation.pptx
 
Robusta -Tool Presentation (DevOps).pptx
Robusta -Tool Presentation (DevOps).pptxRobusta -Tool Presentation (DevOps).pptx
Robusta -Tool Presentation (DevOps).pptx
 
Optimizing Kubernetes using GOLDILOCKS.pptx
Optimizing Kubernetes using GOLDILOCKS.pptxOptimizing Kubernetes using GOLDILOCKS.pptx
Optimizing Kubernetes using GOLDILOCKS.pptx
 
Azure Function App Exception Handling.pptx
Azure Function App Exception Handling.pptxAzure Function App Exception Handling.pptx
Azure Function App Exception Handling.pptx
 
CQRS Design Pattern Presentation (Java).pptx
CQRS Design Pattern Presentation (Java).pptxCQRS Design Pattern Presentation (Java).pptx
CQRS Design Pattern Presentation (Java).pptx
 
ETL Observability: Azure to Snowflake Presentation
ETL Observability: Azure to Snowflake PresentationETL Observability: Azure to Snowflake Presentation
ETL Observability: Azure to Snowflake Presentation
 
Scripting with K6 - Beyond the Basics Presentation
Scripting with K6 - Beyond the Basics PresentationScripting with K6 - Beyond the Basics Presentation
Scripting with K6 - Beyond the Basics Presentation
 
Getting started with dotnet core Web APIs
Getting started with dotnet core Web APIsGetting started with dotnet core Web APIs
Getting started with dotnet core Web APIs
 
Introduction To Rust part II Presentation
Introduction To Rust part II PresentationIntroduction To Rust part II Presentation
Introduction To Rust part II Presentation
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Configuring Workflows & Validators in JIRA
Configuring Workflows & Validators in JIRAConfiguring Workflows & Validators in JIRA
Configuring Workflows & Validators in JIRA
 

Kürzlich hochgeladen

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Kürzlich hochgeladen (20)

MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 

Introduction To Less

  • 1. Ankit Shukla Knoldus Software LLP Ankit Shukla Knoldus Software LLP Less
  • 2. Topics to be Covered ● About Less ● Variables ● Scope ● Mixins ● Nested Rules ● Namespaces ● Operations ● Functions ● Extend ● Mixin Guards ● Loop ● Parent Selector
  • 3. About Less ● Less is a CSS pre-processor, meaning that it extends the CSS language, adding features that allow variables, mixins, functions and many other techniques. ● Developed by Alexis Sellier in 2009. ● The current stable version is 1.7.3 ● Inspired by SASS. ●
  • 4. Variables ● Variables in less are defined with @ ● The assignment is done by : ● It stores a constant value. ● Some properties are used many times in our CSS. It helps to make our code easier to maintain by giving us way to control the repeated properties from a single location.
  • 5. Variables Continues... Less Code: @color : #33333; p{ color : @color; } .demo { background : @color; } Output : p{ color : #333333; } .demo{ background : #333333; }
  • 6. Scope @var: red; #page { #header { @var: white; color: @var; // white } color : @var; } ● Output #page { color: #ff0000; } #page #header { color: #ffffff; }
  • 7. Mixin .demo-class{ color : #aaa; font-size : 20px; } .class-A{ .demo-class; background : #000; } Output: .demo-class { color: #aaa; font-size: 20px; } .class-A{ color : #aaa; font-size : 20px; background : #000; }
  • 8. If you do not want that mixin to be output, you can put parenthesis after it. .mixin { color: black; } .other-mixin() { background: white; } .class { .my-mixin; .other-mixin; } Output: .mixin { color: black; } .class { color: black; background: white; }
  • 9. Parametric Mixins .demo-class(@padding){ padding : @padding; } .class-A{ .demo-class(5px); background : #000; } .class-B{ .demo-class(8px); } Output .class-A{ padding : 5px; background : #000; } .class-B{ padding : 8px; }
  • 10. Nested Rules #header { color: #999; .logo { width: 300px; &:hover{ width:350px; } } } Output: #header { color: #999; } #header .logo { width: 300px; } #header .logo:hover { width: 350px; }
  • 11. Namespaces #bundle { .button { display: block; border: 1px solid black; background-color: grey; } } #header a { color: orange; #bundle > .button; } ● Output #bundle .button { display: block; border: 1px solid black; background-color: grey; } #header a { color: orange; display: block; border: 1px solid black; background-color: grey; }
  • 12. Operations @base: 5%; @filler: @base * 2; @other: @base + @filler; @base-color : #aaa; #class{ color: #888 / 4; background-color: @base-color + #111; height: 100% / 2 + @filler; width : @other + 50%; } ● Output #class { color: #222222; background-color: #bbbbbb; height: 60%; width: 65%; }
  • 13. Functions @base: #f04615; @width: 0.5; .class { width: percentage(@width); color: saturate(@base, 5%); } ● Output .class { width: 50%; color: #f6430f; }
  • 14. Extend ● Extend is a Less Pseudo-Class which merges the selector it is put on with ones that match what it references. ● Extend Syntax : .a:extend(.b) {} or .a { &:extend(.b);}
  • 15. Extend Continues... .a { color : #666; } .b:extend(.a){ font-size : 24px ; } ● Output .a, .b { color: #666; } .b { font-size: 24px ; }
  • 16. Extend All .test.c { color: orange; } .test { color : #555; } .replacement { &:extend(.test all); } ● Output .test.c, .replacement.c { color: orange; } .test, .replacement { color: #555; }
  • 17. Mixin Gaurds .mixin (@a) when (percentage(@a) >= 50%) { background-color: black; } .mixin (@a) when (percentage(@a) < 50%) { background-color: white; } .mixin (@a) { width: percentage(@a); } .class1 { .mixin(.4) } .class2 { .mixin(.6) } ● Output .class1 { background-color: white; width: 40%; } .class2 { background-color: black; width: 60%; }
  • 18. Loop .generate-columns(@n, @i: 1) when (@i =< @n) { .column-@{i} { width: (@i * 100% / @n); } .generate-columns(@n, (@i + 1)); } .generate-columns(2); ● Output .column-1 { width: 50%; } .column-2 { width: 100%; }
  • 19. Parent Selector .A { .B { &:hover{ color :#222; } & & { color: green; } } } ● Output .A .B:hover { color: #222; } .A .B .A .B { color: green; }
  • 20. Parent Selector Continues... .header { .menu { border-radius: 5px; .no-borderradius & { border : none; } } } ● Output .header .menu { border-radius: 5px; } .no-borderradius .header .menu { border: none; }