SlideShare a Scribd company logo
1 of 24
Download to read offline
{less}
( C S S P R E P R O C E S S O R )
R U S H I R A J B R A H M B H AT T
What is 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 that
allow you to make CSS that is more maintainable, themeable and extendable.
• Less can run client side as well as server side.
• Less can be pre-compiled into CSS.
• At first less was written in Ruby ,later it was replaced by JavaScript.
Digging LESS Features
1) VARIABLES
2) MIXINS
a)Parametric Mixins
3) NESTING
a) Nested Rules
b) Conditional Nesting
4) PATTERN MATCHING
5) GUARD EXPRESSIONS (i.e. if statement)
LESS Features Cont..
6) Operators
7) Importing & File Paths
8) Functions
a) Color Functions
b) Math functions
9) NAMESPACES
10)SCOPE
LESS Installation
• Install Node.js in your PC.
– https://nodejs.org/en/
• After installing node open command prompt to install LESS
– npm install -g less
• After installation you can invoke the less compiler from command line by using
“lessc”
– lessc your-file.less
– By this you can see the output of CSS code in your command prompt only.
• To generate .css file in your folder use
– lessc your-file.less your-file.css
– This will generate a CSS file in your folder containing LESS file.
Less Installation Cont..
– Every time you make changes in LESS file you have to run this command to make
changes in CSS too.
– This will generate CSS file in your folder with auto generated pure CSS syntax from
LESS syntax.
• To automatically watch over the LESS file and make changes accordingly in to
CSS file
i. Install less-watch-compiler https://github.com/jonycheung/deadsimple-less-
watch-compiler
ii. In command Prompt
• npm install -g less-watch-compiler
iii. Go into your directory containing less file folder
• less-watch-compiler [LESS-FILE-FOLDER] [CSS-FILE-FOLDER-YOU-WANT-TO-GENERATE]
Less Installation Cont..
• This will watch over the folder in which .less file is there and will generate a
folder containing .css file.
– Example:
• Less-watch-compiler LessFolder CSSFolder
• You can also install less-autocompiler package in any editor you are using.
– Add line of code //out: your-file.css on top of .less file, it will automatically generate
.css file in your folder and will auto update as you update .less file.
Less Installation Cont..
• Client-side is the easiest way to get started and good for developing with Less,
but in production, when performance and reliability is important, it is good to
pre-compile using node.js or one of the many third party tools available.
• To start off, link your .less stylesheets with the rel attribute set to "stylesheet/less"
– <link rel="stylesheet/less" type="text/css" href="styles.less" />
• Next, download less.js and include it in a <script></script> tag in the <head>
element of your page:
– <script src="less.js" type="text/javascript"></script>
NOTE :Using less.js in the browser is great for development, but it's not recommended
for production
Variables
Less Syntax CSS Syntax
Mixins
Less Syntax CSS Syntax
Parametric Mixins
Less Syntax CSS Syntax
Nested Rules
Less Syntax CSS Syntax
Conditional Nesting
Less Syntax CSS Syntax
Pattern Matching
Less Syntax CSS Syntax
When there are two mixins with same name and different parameter sets, Less will match
the parameter pattern and apply the mixin that matches.
Guard Expressions(i.e. if)
LESS Syntax CSS Syntax
.myblock (@size) when (@size < 10){
font-size: @size;
color: red;
}
.myblock (@size) when (@size > 20) and (@size < 30){
font-size: @size;
color: green;
}
.myblock (@size) when (@size = 50),(@size=60){
font-size: @size;
color: blue;
}
.block1{
.myblock(5);
}
.block2 {
.myblock(15);
}
.block3 {
.myblock(50);
}
.block1 {
font-size: 5;
color: red;
}
.block2 {
font-size: 25;
color: green;
}
.block3 {
font-size: 50;
color: blue;
}
Operators
Less Syntax CSS Syntax
Importing
• If your less file is growing, you can make different less files of different sections
and importing those less file into your main less file.
• I have two files button.less and banner.less I have imported these files into my
main.less file.
• It is not necessary to write .less extension while importing, LESS is smart enough it
will understand that imported files are less files.
File Paths
Less Syntax CSS Syntax
Color Function
• LESS have color functions to play with colors. You can lighten the base color or
saturate it, even you can mix two or more different colors.
✓ saturate(@color, @amount)
✓ desaturate(@color, @amount)
✓ lighten(@color, @amount)
✓ darken(@color, @amount)
✓ fadein(@color, @amount)
✓ fadeout(@color, @amount)
✓ fade(@color, @amount)
✓ spin(@color, @amount)
✓ mix(@color1, @color2, @weight)
✓ grayscale(@color)
✓ contrast(@color)
Math Function
• Math operations can be used for standard arithmetic or unit conversions. In
addition to simple math, pre-processors also have complex math support such
as ceiling, rounding, getting min or max value in a list etc.
• LESS provides a couple of math functions you can use on number values:
– round(1.67); // returns '2'
– ceil(2.4); // returns '3'
– floor(2.6); // returns '2'
• If you need to turn a value into a percentage, you can do so with the
percentage function:
– percentage(0.5); // returns '50%'
Namespaces
Less Syntax CSS Syntax
Very useful if you want to create your own CSS libraries or distribute CSS.
Less Syntax CSS Syntax
Scope is similar to other programming languages. Variables and mixins first looked
up locally and then if not found it looks for them in the parent.
Scopes
Resource & Reference
• http://lesscss.org/#
• https://htmlmag.com/article/an-introduction-to-css-preprocessors-sass-less-stylus
THANK YOU
R U S H I R A J B R A H M B H AT T

More Related Content

What's hot

Drupal & CSS Preprocessors
Drupal & CSS PreprocessorsDrupal & CSS Preprocessors
Drupal & CSS Preprocessors
kdmarks
 
Sass: The Future of Stylesheets
Sass: The Future of StylesheetsSass: The Future of Stylesheets
Sass: The Future of Stylesheets
chriseppstein
 
Rupy2012 ArangoDB Workshop Part2
Rupy2012 ArangoDB Workshop Part2Rupy2012 ArangoDB Workshop Part2
Rupy2012 ArangoDB Workshop Part2
ArangoDB Database
 
Advanced WordPress Development Environments
Advanced WordPress Development EnvironmentsAdvanced WordPress Development Environments
Advanced WordPress Development Environments
Beau Lebens
 

What's hot (20)

Sass - basic to advance
Sass  - basic to advanceSass  - basic to advance
Sass - basic to advance
 
Syntactically awesome stylesheets (Sass)
Syntactically awesome stylesheets (Sass)Syntactically awesome stylesheets (Sass)
Syntactically awesome stylesheets (Sass)
 
Sass installation
Sass installationSass installation
Sass installation
 
Using Ansible at Scale to Manage a Public Cloud
Using Ansible at Scale to Manage a Public CloudUsing Ansible at Scale to Manage a Public Cloud
Using Ansible at Scale to Manage a Public Cloud
 
AngularJS Version 1.3
AngularJS  Version 1.3AngularJS  Version 1.3
AngularJS Version 1.3
 
Ch7(publishing my sql data on the web)
Ch7(publishing my sql data on the web)Ch7(publishing my sql data on the web)
Ch7(publishing my sql data on the web)
 
Drupal & CSS Preprocessors
Drupal & CSS PreprocessorsDrupal & CSS Preprocessors
Drupal & CSS Preprocessors
 
SASS Preprocessor
SASS PreprocessorSASS Preprocessor
SASS Preprocessor
 
Sass: The Future of Stylesheets
Sass: The Future of StylesheetsSass: The Future of Stylesheets
Sass: The Future of Stylesheets
 
LESS(CSS preprocessor)
LESS(CSS preprocessor)LESS(CSS preprocessor)
LESS(CSS preprocessor)
 
Wordpress plugin development tips
Wordpress plugin development tipsWordpress plugin development tips
Wordpress plugin development tips
 
Less & Sass
Less & SassLess & Sass
Less & Sass
 
How to Contribute Code to MySQL?
How to Contribute Code to MySQL?How to Contribute Code to MySQL?
How to Contribute Code to MySQL?
 
Rupy2012 ArangoDB Workshop Part2
Rupy2012 ArangoDB Workshop Part2Rupy2012 ArangoDB Workshop Part2
Rupy2012 ArangoDB Workshop Part2
 
Introduction to CouchDB
Introduction to CouchDBIntroduction to CouchDB
Introduction to CouchDB
 
Be Happy With Ruby on Rails - Ecosystem
Be Happy With Ruby on Rails - EcosystemBe Happy With Ruby on Rails - Ecosystem
Be Happy With Ruby on Rails - Ecosystem
 
Advanced WordPress Development Environments
Advanced WordPress Development EnvironmentsAdvanced WordPress Development Environments
Advanced WordPress Development Environments
 
PostgreSQL - It's kind've a nifty database
PostgreSQL - It's kind've a nifty databasePostgreSQL - It's kind've a nifty database
PostgreSQL - It's kind've a nifty database
 
Configuring a more secure BOSH
Configuring a more secure BOSHConfiguring a more secure BOSH
Configuring a more secure BOSH
 
Cloud Computing Training
Cloud Computing TrainingCloud Computing Training
Cloud Computing Training
 

Similar to Less(CSS Pre Processor) Introduction

SASS is more than LESS
SASS is more than LESSSASS is more than LESS
SASS is more than LESS
Itai Koren
 

Similar to Less(CSS Pre Processor) Introduction (20)

UNIT 3.ppt
UNIT 3.pptUNIT 3.ppt
UNIT 3.ppt
 
LESS CSS
LESS CSSLESS CSS
LESS CSS
 
Start using less css
Start using less cssStart using less css
Start using less css
 
Why less?
Why less?Why less?
Why less?
 
Introducing grunt, npm and sass
Introducing grunt, npm and sassIntroducing grunt, npm and sass
Introducing grunt, npm and sass
 
CSS Less framework overview, Pros and Cons
CSS Less framework overview, Pros and ConsCSS Less framework overview, Pros and Cons
CSS Less framework overview, Pros and Cons
 
SASS is more than LESS
SASS is more than LESSSASS is more than LESS
SASS is more than LESS
 
Scss talk CSS Meetup
Scss talk CSS Meetup Scss talk CSS Meetup
Scss talk CSS Meetup
 
SCSS Implementation
SCSS ImplementationSCSS Implementation
SCSS Implementation
 
Less - an Introduction
Less - an IntroductionLess - an Introduction
Less - an Introduction
 
Advanced sass/compass
Advanced sass/compassAdvanced sass/compass
Advanced sass/compass
 
Advanced sass
Advanced sassAdvanced sass
Advanced sass
 
An Introduction to CSS Preprocessors (SASS & LESS)
An Introduction to CSS Preprocessors (SASS & LESS)An Introduction to CSS Preprocessors (SASS & LESS)
An Introduction to CSS Preprocessors (SASS & LESS)
 
Doing More With Less
Doing More With LessDoing More With Less
Doing More With Less
 
Sass_Cubet seminar
Sass_Cubet seminarSass_Cubet seminar
Sass_Cubet seminar
 
CSS 開發加速指南-Sass & Compass
CSS 開發加速指南-Sass & CompassCSS 開發加速指南-Sass & Compass
CSS 開發加速指南-Sass & Compass
 
Create SASSy web parts in SPFx
Create SASSy web parts in SPFxCreate SASSy web parts in SPFx
Create SASSy web parts in SPFx
 
[Bauer] SASSy web parts with SPFX
[Bauer] SASSy web parts with SPFX[Bauer] SASSy web parts with SPFX
[Bauer] SASSy web parts with SPFX
 
Deep dive into sass
Deep dive into sassDeep dive into sass
Deep dive into sass
 
Intro to Sass for WordPress Developers
Intro to Sass for WordPress DevelopersIntro to Sass for WordPress Developers
Intro to Sass for WordPress Developers
 

Recently uploaded

Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Krashi Coaching
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
fonyou31
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Recently uploaded (20)

Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 

Less(CSS Pre Processor) Introduction

  • 1. {less} ( C S S P R E P R O C E S S O R ) R U S H I R A J B R A H M B H AT T
  • 2. What is 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 that allow you to make CSS that is more maintainable, themeable and extendable. • Less can run client side as well as server side. • Less can be pre-compiled into CSS. • At first less was written in Ruby ,later it was replaced by JavaScript.
  • 3. Digging LESS Features 1) VARIABLES 2) MIXINS a)Parametric Mixins 3) NESTING a) Nested Rules b) Conditional Nesting 4) PATTERN MATCHING 5) GUARD EXPRESSIONS (i.e. if statement)
  • 4. LESS Features Cont.. 6) Operators 7) Importing & File Paths 8) Functions a) Color Functions b) Math functions 9) NAMESPACES 10)SCOPE
  • 5. LESS Installation • Install Node.js in your PC. – https://nodejs.org/en/ • After installing node open command prompt to install LESS – npm install -g less • After installation you can invoke the less compiler from command line by using “lessc” – lessc your-file.less – By this you can see the output of CSS code in your command prompt only. • To generate .css file in your folder use – lessc your-file.less your-file.css – This will generate a CSS file in your folder containing LESS file.
  • 6. Less Installation Cont.. – Every time you make changes in LESS file you have to run this command to make changes in CSS too. – This will generate CSS file in your folder with auto generated pure CSS syntax from LESS syntax. • To automatically watch over the LESS file and make changes accordingly in to CSS file i. Install less-watch-compiler https://github.com/jonycheung/deadsimple-less- watch-compiler ii. In command Prompt • npm install -g less-watch-compiler iii. Go into your directory containing less file folder • less-watch-compiler [LESS-FILE-FOLDER] [CSS-FILE-FOLDER-YOU-WANT-TO-GENERATE]
  • 7. Less Installation Cont.. • This will watch over the folder in which .less file is there and will generate a folder containing .css file. – Example: • Less-watch-compiler LessFolder CSSFolder • You can also install less-autocompiler package in any editor you are using. – Add line of code //out: your-file.css on top of .less file, it will automatically generate .css file in your folder and will auto update as you update .less file.
  • 8. Less Installation Cont.. • Client-side is the easiest way to get started and good for developing with Less, but in production, when performance and reliability is important, it is good to pre-compile using node.js or one of the many third party tools available. • To start off, link your .less stylesheets with the rel attribute set to "stylesheet/less" – <link rel="stylesheet/less" type="text/css" href="styles.less" /> • Next, download less.js and include it in a <script></script> tag in the <head> element of your page: – <script src="less.js" type="text/javascript"></script> NOTE :Using less.js in the browser is great for development, but it's not recommended for production
  • 14. Pattern Matching Less Syntax CSS Syntax When there are two mixins with same name and different parameter sets, Less will match the parameter pattern and apply the mixin that matches.
  • 15. Guard Expressions(i.e. if) LESS Syntax CSS Syntax .myblock (@size) when (@size < 10){ font-size: @size; color: red; } .myblock (@size) when (@size > 20) and (@size < 30){ font-size: @size; color: green; } .myblock (@size) when (@size = 50),(@size=60){ font-size: @size; color: blue; } .block1{ .myblock(5); } .block2 { .myblock(15); } .block3 { .myblock(50); } .block1 { font-size: 5; color: red; } .block2 { font-size: 25; color: green; } .block3 { font-size: 50; color: blue; }
  • 17. Importing • If your less file is growing, you can make different less files of different sections and importing those less file into your main less file. • I have two files button.less and banner.less I have imported these files into my main.less file. • It is not necessary to write .less extension while importing, LESS is smart enough it will understand that imported files are less files.
  • 19. Color Function • LESS have color functions to play with colors. You can lighten the base color or saturate it, even you can mix two or more different colors. ✓ saturate(@color, @amount) ✓ desaturate(@color, @amount) ✓ lighten(@color, @amount) ✓ darken(@color, @amount) ✓ fadein(@color, @amount) ✓ fadeout(@color, @amount) ✓ fade(@color, @amount) ✓ spin(@color, @amount) ✓ mix(@color1, @color2, @weight) ✓ grayscale(@color) ✓ contrast(@color)
  • 20. Math Function • Math operations can be used for standard arithmetic or unit conversions. In addition to simple math, pre-processors also have complex math support such as ceiling, rounding, getting min or max value in a list etc. • LESS provides a couple of math functions you can use on number values: – round(1.67); // returns '2' – ceil(2.4); // returns '3' – floor(2.6); // returns '2' • If you need to turn a value into a percentage, you can do so with the percentage function: – percentage(0.5); // returns '50%'
  • 21. Namespaces Less Syntax CSS Syntax Very useful if you want to create your own CSS libraries or distribute CSS.
  • 22. Less Syntax CSS Syntax Scope is similar to other programming languages. Variables and mixins first looked up locally and then if not found it looks for them in the parent. Scopes
  • 23. Resource & Reference • http://lesscss.org/# • https://htmlmag.com/article/an-introduction-to-css-preprocessors-sass-less-stylus
  • 24. THANK YOU R U S H I R A J B R A H M B H AT T