SlideShare uma empresa Scribd logo
1 de 24
The power to take advantage
of dynamic behavior
b
Agenda
• What is {Less}?
• Why {Less}?
• Implementation of {Less} in websites.
• Comparison between Less and Sass
• Overview of the syntax with examples.
b
What is {Less}?
• Dynamic style sheet language designed by Alexis Sellier from
Berlin - @cloudhead.
• Open source - Apache 2 License.
• Less was designed as a Nested metalanguage
- valid CSS is valid Less code with the same semantics.
• Less can run client-side (IE8+, WebKit, Firefox).
• Less can run server-side (Node.js).
• Less can be pre-compiled into CSS.
• First version of was written in Ruby but this was replaced by a
JavaScript version.
b
Why {Less}?
• Save time
• Reduce mistakes
• Reduce repetition
• It makes logical sense to break out CSS into multiple files
• More Readability
b
Implementation of {Less} in
websites.
• Let the website convert the Less code to CSS on the fly by
including the less.js file – available from http://www.lesscss.org
• Download less.js from www.lesscss.org
• Add your Less CSS code to a text file with a .less extension eg.
styles.less
• Include less.js with your styles:
<link rel="stylesheet/less" type="text/css" href="styles.less">
<script src="less.js" type="text/javascript"></script>
b
Comparison between Less and Sass
• Sass is more mature and has slightly more features[compass ]
• They are pre-processed differently:
• Less uses JavaScript and can run client-side.
• Sass uses Ruby so runs server-side.
• Less can be slower to compile on the fly when running client-
side.
• Both can be pre-compiled into pure CSS before uploading
style sheets to sites – meaning no difference in performance.
• Syntax - https://gist.github.com/674726
• https://gist.github.com/wilmoore/820035
• http://www.hongkiat.com/blog/sass-vs-less/
•
http://www.quora.com/Which-is-better-Less-Compass-or-Sass
b
Less CSS compilers
Respectively all major editors can be used for writing
{Less}
• Free compiler for mac –
http://incident57.com/less
• Free compiler for mac, pc, Linux –
http://wearekiss.com/simpless
http://winless.org/online-less-compiler
WinLess
Crunch!
Mixture
Adobe Dream Weaver
Notepad++
Sublime Text 2
Kineticwing IDE
Coda
Geany
b
Syntax with examples.
-LESS has everything that CSS is missing. {Less} allows the
dynamic editability options for dynamic stylesheet with help of
these
• Variables
• Mixins
• Cascading + Nesting
• &combinator
• Operations
• Comments
• @import
• String interpolation
• Escaping
• Namespaces
• Scope
• Extend
• Loops
b
Variables
• Start with @ symbol
• Can storehexadecimalcolors, e.g. #333 or #fefefe
• Can store strings, e.g. “Webucator, Inc.”
• Can store sizes, e.g. 10px
LESS Syntax CSS Output
// Declare a numeric variable
@red: #ff0000;
// Declare a string variable
@path: "/sites/default/files/images";
// Apply these variables
.block {
color: @red;
background:url('@{path}/mypic.jpg');
}
.block {
color: #ff0000;
background: url('/sites/default/
files/images/mypic.jpg');
}
b
Mixins
• Include properties from one ruleset to another
• Reuse code
• Can accept parameters
• Can define default value for parameters
• @arguments is a special variable that contains the ordered
value stored in all parameters
LESS Syntax CSS Output
.border-radius(@radius: 2px) {
-webkit-border-radius: @radius;
-moz-border-radius: @radius;
border-radius: @radius;
}
@gray: #333;
header > nav {
border:1px solid @gray;
.border-radius;
}
aside > nav {
.border-radius(5px);
}
header > nav {
border:1px solid #333;
-webkit-border-radius: 2px;
-moz-border-radius: 2px;
border-radius: 2px;
}
aside > nav {
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
}
b
Cascading + Nesting
• Nest rulesets in place of cascading
• Can be used in combination with traditional cascading
approach
• Mimics your DOM structure
• Outputs to cascading rulesets
LESS Syntax LESS Nesting
header {
color: white;
}
header .logo {
width:300px;
float:left;
}
header > #searchcontainer {
width:300px;
float:right;
}
header > #searchcontainer input {
width:250px;
margin-right:6px;
color:@darkGray;
}
header > #searchcontainer input:focus
{
color:@lightGray;
}
header {
color: white;
.logo {
width:300px;
float:left;
}
#searchcontainer {
width:300px;
float:right;
input {
width:250px;
margin-right:6px;
color:@darkGray;
&:focus {
color:@lightGray;
}
}
}
}
b
&combinator
• Nested selector is concatenated to the parent selector
• Useful for pseudo-classes
• &:hover
• &:focus
LESS Syntax CSS Output
@gray: #333;
img {
border:none;
&:focus {
border:1px solid @gray;
}
@.inline {
display:inline;
}
}
img {
border:none;
}
img:focus {
border:1px solid #333;
}
img.inline {
display:inline;
}
b
Operations
- which let you create CSS properties mathematically.
• Any number, color or variable can be operated upon
• Math functions
• Math operators ( +, -, *, /)
• Color functions
LESS Syntax CSS Output
@padding: 2px;
figure {
padding:@padding;
img {
padding:@padding * 2;
}
figcaption {
padding:@padding + 4px;
}
}
figure {
padding:2px;
}
figure img {
padding:4px;
}
figure figcaption {
padding: 6px;
}
b
Comments
Comments are pretty straight-forward in LESS. Multiline
comments are preserved and included in the CSS output when
you compile the LESS, and single line comments are not
preserved. Therefore, you should generally use single line
comments, unless you really need the comment to be included
in the generated CSS.
• /* These comments are preserved into your compiled CSS */
• // These comments are silent
b
@import
• @import will compile and copy result into single file
• All variables and mixins are available to main file or files
imported after declarations
• Order matters
• Can include/ignore .less extension
• Can import “classic” css using .css extension
• You can break out files logically, but avoid the (terrible)
@import() statement in traditional CSS
LESS @IMPORT Syntax
// import normalize for CSS resets
@import "normalize";
// same as @import “normalize.less”;
// import mixins
@import "mixins";
// base for mobile devices
@import "base";
//tables and small laptops
@media only screen and (min-width: 768px) {
@import "768up";
}
//desktop
@media only screen and (min-width: 1030px) {
@import "1030up";
}
b
String Interpolation
• Use @{name} construct
• For embedding variable values within declarations
@baseUrl: “http://www.webucator.com/”;
@imageUri: “images/”;
background-image: url(‘@{baseUrl}@{imageUri}bg.png’);
background-image: url(‘http://www.webucator.com/images/bg.png’);
b
Namespaces
- Groups of styles that can be called by references.
- Very useful if you want to create your own CSS libraries or
distribute CSS
LESS Syntax CSS Output
#my_framework{
p{
margin:12px 0;
}
a{
color:blue;
text-decoration:none;
}
.submit{
background:red;
color:white;
padding:5px 12px;
}
}
.submit_button{
#my_framework > .submit;
}
#my_framework p{
margin:12px 0;
}
#my_framework a{
color:blue;
text-decoration:none;
}
#my_framework .submit{
background:red;
color:white;
padding:5px 12px;
}
.submit_button{
background:red;
color:white;
padding:5px 12px;
}
b
Scope
- Scope in Less is very similar to that of programming
languages. Variables and mixins are first looked for locally, and
if they aren't found, the compiler will look in the parent scope,
and so on.
LESS Scope Syntax
@var: red;
#page {
@var: white;
#header {
color: @var; // white
}
}
#footer {
color: @var; // red
}
b
Extend
- Extend is a Less pseudo-class which merges the selector it is
put on with ones that match what it references.
LESS Syntax CSS Output
nav ul {
&:extend(.inline);
background: blue;
}
.inline {
color: red;
}
nav ul {
background: blue;
}
.inline,
nav ul {
color: red;
}
b
Loops
- Creating loops
LESS Syntax CSS Output
.loop(@counter) when (@counter > 0) {
.loop((@counter - 1)); // next
iteration
width: (10px * @counter); // code for
each iteration
}
div {
.loop(5); // launch the loop
}
div {
width: 10px;
width: 20px;
width: 30px;
width: 40px;
width: 50px;
}
LESS Syntax CSS Output
.generate-columns(4);
.generate-columns(@n, @i: 1) when
(@i =< @n) {
.column-@{i} {
width: (@i * 100% / @n);
}
.generate-columns(@n, (@i + 1));
}
.column-1 {
width: 25%;
}
.column-2 {
width: 50%;
}
.column-3 {
width: 75%;
}
.column-4 {
width: 100%;
}
b
My Perspective
• It's easy to install, you can use a JavaScript file for client side
compiling during development, and there are several ways to
compile the less files to CSS server side for production.
• Syntax very close to original CSS.
• Easy to Understand
In the end, it is still up to the end-user’s decision to pick the
preprocessor of their choice. Be it Sass or LESS, as long as they are
comfortable and more productive.
b
References
• http://lesscss.org/features/
•
http://css-tricks.com/snippets/javascript/lighten-darken-color/
•
https://stackoverflow.com/questions/21821947/calculate-differen
• https://github.com/less/less.js/archive/master.zip
• http://www.lesscss.org
• http://leafo.net/lessphp
• http://sass-lang.com
• https://github.com/cloudhead
• http://en.wikipedia.org/wiki/LESS_(stylesheet_language)
• http://coding.smashingmagazine.com/2011/09/09/an-
introduction-to-less-and-comparison-to-sass
b
Thank You 

Mais conteúdo relacionado

Mais procurados

Dallas Drupal Days 2012 - Introduction to less sass-compass
Dallas Drupal Days 2012  - Introduction to less sass-compassDallas Drupal Days 2012  - Introduction to less sass-compass
Dallas Drupal Days 2012 - Introduction to less sass-compass
Chris Lee
 
Week01 jan19 introductionto_php
Week01 jan19 introductionto_phpWeek01 jan19 introductionto_php
Week01 jan19 introductionto_php
Jeanho Chu
 

Mais procurados (20)

Less
LessLess
Less
 
Sass presentation
Sass presentationSass presentation
Sass presentation
 
SASS - CSS with Superpower
SASS - CSS with SuperpowerSASS - CSS with Superpower
SASS - CSS with Superpower
 
Syntactically awesome stylesheets (Sass)
Syntactically awesome stylesheets (Sass)Syntactically awesome stylesheets (Sass)
Syntactically awesome stylesheets (Sass)
 
Introduction to sass
Introduction to sassIntroduction to sass
Introduction to sass
 
Deep dive into sass
Deep dive into sassDeep dive into sass
Deep dive into sass
 
Developer skills
Developer skillsDeveloper skills
Developer skills
 
Dallas Drupal Days 2012 - Introduction to less sass-compass
Dallas Drupal Days 2012  - Introduction to less sass-compassDallas Drupal Days 2012  - Introduction to less sass-compass
Dallas Drupal Days 2012 - Introduction to less sass-compass
 
Beautifying senc
Beautifying sencBeautifying senc
Beautifying senc
 
Bliblidotcom - SASS Introduction
Bliblidotcom - SASS IntroductionBliblidotcom - SASS Introduction
Bliblidotcom - SASS Introduction
 
Responsive Design in Drupal with Zen and Zen Grids
Responsive Design in Drupal with Zen and Zen GridsResponsive Design in Drupal with Zen and Zen Grids
Responsive Design in Drupal with Zen and Zen Grids
 
Sass Beginner Guide
Sass Beginner GuideSass Beginner Guide
Sass Beginner Guide
 
SASS for WordPress Workshop
SASS for WordPress WorkshopSASS for WordPress Workshop
SASS for WordPress Workshop
 
The web context
The web contextThe web context
The web context
 
Journey To The Front End World - Part2 - The Cosmetic
Journey To The Front End World - Part2 - The  CosmeticJourney To The Front End World - Part2 - The  Cosmetic
Journey To The Front End World - Part2 - The Cosmetic
 
SharePoint 2010 branding
SharePoint 2010 brandingSharePoint 2010 branding
SharePoint 2010 branding
 
Advanced sass
Advanced sassAdvanced sass
Advanced sass
 
Css Preprocessors
Css PreprocessorsCss Preprocessors
Css Preprocessors
 
Week01 jan19 introductionto_php
Week01 jan19 introductionto_phpWeek01 jan19 introductionto_php
Week01 jan19 introductionto_php
 
From CSS to Sass in WordPress
From CSS to Sass in WordPressFrom CSS to Sass in WordPress
From CSS to Sass in WordPress
 

Semelhante a LESS CSS

CSS preprocessor: why and how
CSS preprocessor: why and howCSS preprocessor: why and how
CSS preprocessor: why and how
mirahman
 

Semelhante a LESS CSS (20)

UNIT 3.ppt
UNIT 3.pptUNIT 3.ppt
UNIT 3.ppt
 
Less(CSS Pre Processor) Introduction
Less(CSS Pre Processor) IntroductionLess(CSS Pre Processor) Introduction
Less(CSS Pre Processor) Introduction
 
LESS(CSS Pre Processor) introduction
LESS(CSS Pre Processor) introductionLESS(CSS Pre Processor) introduction
LESS(CSS Pre Processor) introduction
 
Write LESS. DO more.
Write LESS. DO more.Write LESS. DO more.
Write LESS. DO more.
 
CSS 開發加速指南-Sass & Compass
CSS 開發加速指南-Sass & CompassCSS 開發加速指南-Sass & Compass
CSS 開發加速指南-Sass & Compass
 
Advanced sass/compass
Advanced sass/compassAdvanced sass/compass
Advanced sass/compass
 
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)
 
Getting Started with Sass & Compass
Getting Started with Sass & CompassGetting Started with Sass & Compass
Getting Started with 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
 
Doing More With Less
Doing More With LessDoing More With Less
Doing More With Less
 
What is LessCSS and its Detailed Explation - Xhtmlchop
What is LessCSS and its Detailed Explation - XhtmlchopWhat is LessCSS and its Detailed Explation - Xhtmlchop
What is LessCSS and its Detailed Explation - Xhtmlchop
 
PostCss
PostCssPostCss
PostCss
 
Preprocessor presentation
Preprocessor presentationPreprocessor presentation
Preprocessor presentation
 
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
 
CSS3
CSS3CSS3
CSS3
 
Css preprocessor-140606115334-phpapp01
Css preprocessor-140606115334-phpapp01Css preprocessor-140606115334-phpapp01
Css preprocessor-140606115334-phpapp01
 
CSS preprocessor: why and how
CSS preprocessor: why and howCSS preprocessor: why and how
CSS preprocessor: why and how
 
Fasten RWD Development with Sass
Fasten RWD Development with SassFasten RWD Development with Sass
Fasten RWD Development with Sass
 
Create SASSY Web Parts - SPSMilan
Create SASSY Web Parts - SPSMilan Create SASSY Web Parts - SPSMilan
Create SASSY Web Parts - SPSMilan
 

Último

The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 

Último (20)

call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT  - Elevating Productivity in Today's Agile EnvironmentHarnessing ChatGPT  - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 

LESS CSS

  • 1. The power to take advantage of dynamic behavior
  • 2. b Agenda • What is {Less}? • Why {Less}? • Implementation of {Less} in websites. • Comparison between Less and Sass • Overview of the syntax with examples.
  • 3. b What is {Less}? • Dynamic style sheet language designed by Alexis Sellier from Berlin - @cloudhead. • Open source - Apache 2 License. • Less was designed as a Nested metalanguage - valid CSS is valid Less code with the same semantics. • Less can run client-side (IE8+, WebKit, Firefox). • Less can run server-side (Node.js). • Less can be pre-compiled into CSS. • First version of was written in Ruby but this was replaced by a JavaScript version.
  • 4. b Why {Less}? • Save time • Reduce mistakes • Reduce repetition • It makes logical sense to break out CSS into multiple files • More Readability
  • 5. b Implementation of {Less} in websites. • Let the website convert the Less code to CSS on the fly by including the less.js file – available from http://www.lesscss.org • Download less.js from www.lesscss.org • Add your Less CSS code to a text file with a .less extension eg. styles.less • Include less.js with your styles: <link rel="stylesheet/less" type="text/css" href="styles.less"> <script src="less.js" type="text/javascript"></script>
  • 6. b Comparison between Less and Sass • Sass is more mature and has slightly more features[compass ] • They are pre-processed differently: • Less uses JavaScript and can run client-side. • Sass uses Ruby so runs server-side. • Less can be slower to compile on the fly when running client- side. • Both can be pre-compiled into pure CSS before uploading style sheets to sites – meaning no difference in performance. • Syntax - https://gist.github.com/674726 • https://gist.github.com/wilmoore/820035 • http://www.hongkiat.com/blog/sass-vs-less/ • http://www.quora.com/Which-is-better-Less-Compass-or-Sass
  • 7. b Less CSS compilers Respectively all major editors can be used for writing {Less} • Free compiler for mac – http://incident57.com/less • Free compiler for mac, pc, Linux – http://wearekiss.com/simpless http://winless.org/online-less-compiler WinLess Crunch! Mixture Adobe Dream Weaver Notepad++ Sublime Text 2 Kineticwing IDE Coda Geany
  • 8. b Syntax with examples. -LESS has everything that CSS is missing. {Less} allows the dynamic editability options for dynamic stylesheet with help of these • Variables • Mixins • Cascading + Nesting • &combinator • Operations • Comments • @import • String interpolation • Escaping • Namespaces • Scope • Extend • Loops
  • 9. b Variables • Start with @ symbol • Can storehexadecimalcolors, e.g. #333 or #fefefe • Can store strings, e.g. “Webucator, Inc.” • Can store sizes, e.g. 10px LESS Syntax CSS Output // Declare a numeric variable @red: #ff0000; // Declare a string variable @path: "/sites/default/files/images"; // Apply these variables .block { color: @red; background:url('@{path}/mypic.jpg'); } .block { color: #ff0000; background: url('/sites/default/ files/images/mypic.jpg'); }
  • 10. b Mixins • Include properties from one ruleset to another • Reuse code • Can accept parameters • Can define default value for parameters • @arguments is a special variable that contains the ordered value stored in all parameters LESS Syntax CSS Output .border-radius(@radius: 2px) { -webkit-border-radius: @radius; -moz-border-radius: @radius; border-radius: @radius; } @gray: #333; header > nav { border:1px solid @gray; .border-radius; } aside > nav { .border-radius(5px); } header > nav { border:1px solid #333; -webkit-border-radius: 2px; -moz-border-radius: 2px; border-radius: 2px; } aside > nav { -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; }
  • 11. b Cascading + Nesting • Nest rulesets in place of cascading • Can be used in combination with traditional cascading approach • Mimics your DOM structure • Outputs to cascading rulesets LESS Syntax LESS Nesting header { color: white; } header .logo { width:300px; float:left; } header > #searchcontainer { width:300px; float:right; } header > #searchcontainer input { width:250px; margin-right:6px; color:@darkGray; } header > #searchcontainer input:focus { color:@lightGray; } header { color: white; .logo { width:300px; float:left; } #searchcontainer { width:300px; float:right; input { width:250px; margin-right:6px; color:@darkGray; &:focus { color:@lightGray; } } } }
  • 12. b &combinator • Nested selector is concatenated to the parent selector • Useful for pseudo-classes • &:hover • &:focus LESS Syntax CSS Output @gray: #333; img { border:none; &:focus { border:1px solid @gray; } @.inline { display:inline; } } img { border:none; } img:focus { border:1px solid #333; } img.inline { display:inline; }
  • 13. b Operations - which let you create CSS properties mathematically. • Any number, color or variable can be operated upon • Math functions • Math operators ( +, -, *, /) • Color functions LESS Syntax CSS Output @padding: 2px; figure { padding:@padding; img { padding:@padding * 2; } figcaption { padding:@padding + 4px; } } figure { padding:2px; } figure img { padding:4px; } figure figcaption { padding: 6px; }
  • 14. b Comments Comments are pretty straight-forward in LESS. Multiline comments are preserved and included in the CSS output when you compile the LESS, and single line comments are not preserved. Therefore, you should generally use single line comments, unless you really need the comment to be included in the generated CSS. • /* These comments are preserved into your compiled CSS */ • // These comments are silent
  • 15. b @import • @import will compile and copy result into single file • All variables and mixins are available to main file or files imported after declarations • Order matters • Can include/ignore .less extension • Can import “classic” css using .css extension • You can break out files logically, but avoid the (terrible) @import() statement in traditional CSS LESS @IMPORT Syntax // import normalize for CSS resets @import "normalize"; // same as @import “normalize.less”; // import mixins @import "mixins"; // base for mobile devices @import "base"; //tables and small laptops @media only screen and (min-width: 768px) { @import "768up"; } //desktop @media only screen and (min-width: 1030px) { @import "1030up"; }
  • 16. b String Interpolation • Use @{name} construct • For embedding variable values within declarations @baseUrl: “http://www.webucator.com/”; @imageUri: “images/”; background-image: url(‘@{baseUrl}@{imageUri}bg.png’); background-image: url(‘http://www.webucator.com/images/bg.png’);
  • 17. b Namespaces - Groups of styles that can be called by references. - Very useful if you want to create your own CSS libraries or distribute CSS LESS Syntax CSS Output #my_framework{ p{ margin:12px 0; } a{ color:blue; text-decoration:none; } .submit{ background:red; color:white; padding:5px 12px; } } .submit_button{ #my_framework > .submit; } #my_framework p{ margin:12px 0; } #my_framework a{ color:blue; text-decoration:none; } #my_framework .submit{ background:red; color:white; padding:5px 12px; } .submit_button{ background:red; color:white; padding:5px 12px; }
  • 18. b Scope - Scope in Less is very similar to that of programming languages. Variables and mixins are first looked for locally, and if they aren't found, the compiler will look in the parent scope, and so on. LESS Scope Syntax @var: red; #page { @var: white; #header { color: @var; // white } } #footer { color: @var; // red }
  • 19. b Extend - Extend is a Less pseudo-class which merges the selector it is put on with ones that match what it references. LESS Syntax CSS Output nav ul { &:extend(.inline); background: blue; } .inline { color: red; } nav ul { background: blue; } .inline, nav ul { color: red; }
  • 20. b Loops - Creating loops LESS Syntax CSS Output .loop(@counter) when (@counter > 0) { .loop((@counter - 1)); // next iteration width: (10px * @counter); // code for each iteration } div { .loop(5); // launch the loop } div { width: 10px; width: 20px; width: 30px; width: 40px; width: 50px; } LESS Syntax CSS Output .generate-columns(4); .generate-columns(@n, @i: 1) when (@i =< @n) { .column-@{i} { width: (@i * 100% / @n); } .generate-columns(@n, (@i + 1)); } .column-1 { width: 25%; } .column-2 { width: 50%; } .column-3 { width: 75%; } .column-4 { width: 100%; }
  • 21. b My Perspective • It's easy to install, you can use a JavaScript file for client side compiling during development, and there are several ways to compile the less files to CSS server side for production. • Syntax very close to original CSS. • Easy to Understand In the end, it is still up to the end-user’s decision to pick the preprocessor of their choice. Be it Sass or LESS, as long as they are comfortable and more productive.
  • 22. b References • http://lesscss.org/features/ • http://css-tricks.com/snippets/javascript/lighten-darken-color/ • https://stackoverflow.com/questions/21821947/calculate-differen • https://github.com/less/less.js/archive/master.zip • http://www.lesscss.org • http://leafo.net/lessphp • http://sass-lang.com • https://github.com/cloudhead • http://en.wikipedia.org/wiki/LESS_(stylesheet_language) • http://coding.smashingmagazine.com/2011/09/09/an- introduction-to-less-and-comparison-to-sass
  • 23. b