Write LESS. DO more.

Eugene Nor
Eugene NorWeb UI developer um SoftServe
DO MORE.
WRITE LESS.
Eugene Nor
SoftServe
What is LESS?
 Less – preprocessor language that extends usual
CSS to make it more readable and maintainable.
 Outputs the code to pure CSS
 Adds semantic and structure to stylesheets
 Makes coding slightly faster
 …and fun (most of the time)
Example
Less code:
@base: #f938ab;
@text: saturate(@base, 5%);
.shadow(@style, @c: #f5f5f5) {
-webkit-box-shadow: @style @c;
box-shadow: @style @c;
border: 1px solid @c;
}
.box {
color: @text;
div {
.shadow(0 0 5px, @base)
}
}
CSS output:
.box {
color: #fe33ac;
}
.box div {
-webkit-box-shadow: 0 0 5px #fdcdea;
box-shadow: 0 0 5px #fdcdea);
border: 1px solid #fdcdea);
}
Some history
 Less was created in 2009 by Alexis Sellier, more commonly
known as @cloudhead. Originally written in Ruby, it was
then ported to JavaScript.
 In May 2012 Alexis relinquished control and development
over to a core team of contributors who now manage, fix
and extend the language.
 Less is maintained by a group of invaluable core
contributors, with the massive support and involvement of
our community.
Installation & usage
 Less can be used on command line as Node package (make sure you
have NodeJS installed):
npm install less –g
 After successful installation you can use it next ways:
 $ lessc styles.less - this will output the compiled CSS to stdout
 $ lessc styles.less > styles.css - will output CSS to file styles.css
 $ lessc styles.less > styles.css –x - will output minified CSS
Installation & usage
 Also it’s possible to use LESS as a Grunt task:
npm install grunt-contrib-less --save-dev
 Gruntfile:
less: {
development: {
options: {
paths: ["assets/css"]
},
files: {
"path/to/result.css": "path/to/source.less"
}
}
grunt.loadNpmTasks('grunt-contrib-less');
Installation & usage
 Include it a script file for the browser (not recommended for production).
 Make sure you include your stylesheets before the script.
 You can add some options for convenient debugging.
<script>
less = {
env: "development",
async: false,
fileAsync: false,
poll: 1000,
functions: {},
relativeUrls: false,
rootpath: ":/a.com/“
};
</script>
<script src="less.js"></script>
<script>less.watch();</script> <!—This enables live browser reload-->
Nested rules
 Less allows you to nest selectors one into another just the same as
they are placed in HTML:
Less code:
#header {
color: black;
.navigation {
font-size: 12px;
}
.logo {
width: 300px;
}
}
CSS output:
#header {
color: black;
}
#header .navigation {
font-size: 12px;
}
#header .logo {
width: 300px;
}
Variables
 Define variables and refer to them in your rules.
 When defining a variable twice, the last definition of the variable is
used, searching from the current scope upwards (scopes work just like
in JavaScript)
@var: 0;
.class1 {
@var: 1;
.class {
@var: 2;
three: @var;
@var: 3;
}
one: @var;
}
@nice-blue: #5B83AD;
@light-blue: @nice-blue + #111;
#header {
color: @light-blue;
border-color: @nice-blue;
}
Arithmetic
 Any number, color or variable in Less can be operated:
@base: 5%;
@filler: @base * 2;
@other: @base + @filler;
color: #888 / 4;
background-color: @base-color + #111;
height: 100% / 2 + @filler;
 LESS understands units well:
@var: 1px + 5; //6px
Mixins
 Mixins are a way of including ("mixing in") a bunch of properties from
one rule-set into another rule-set
Definition:
.bordered {
border-top: dotted 1px black;
border-bottom: solid 2px black;
}
.no-decoration {
text-decoration: none;
}
Usage:
#menu a {
color: #111;
.no-decoration;
}
.post a {
color: red;
.bordered;
}
Mixins without output
 Mixin can be created without output to result style:
CSS output:
.my-mixin {
color: black;
}
.class {
color: black;
background-color: white;
}
Less code:
.my-mixin {
color: black;
}
.my-other-mixin() {
background-color: white;
}
.class {
.my-mixin;
.my-other-mixin;
}
This!
 & symbol represents the current parent selector (such as this keyword
in JavaScript)
CSS output:
button :hover {
border: 1px solid red;
}
Less code:
.my-hover-mixin() {
&:hover {
border: 1px solid red;
}
}
button {
.my-hover-mixin();
}
Parametric mixins
 Pass parameters to mixins to make them more versatile.
 It’s possible to declare default values of parameters in mixin definition.
Definition:
.border-radius(@radius: 10px) {
-webkit-border-radius: @radius;
-moz-border-radius: @radius;
border-radius: @radius;
}
Usage:
#header {
.border-radius(4px);
}
.button {
.border-radius(6px);
}
Mixin guards
 Guards in Less are useful for conditional declaration of mixins
 Guards allows you to check value of a parameter as well as its type
.mixin (@a) when (lightness(@a) >= 50%) {
background-color: black;
}
.mixin (@a) when (lightness(@a) < 50%) {
background-color: white;
}
.mixin (@a) {
color: @a;
}
.another-mixin (@a; @b: 0) when (isnumber(@b)) { ... }
.another-mixin (@a; @b: black) when (iscolor(@b)) { ... }
Return variables
 All variables defined in a mixin are visible and can be used in caller's
scope. This allows to create mixins that can be used almost like a
functions
.average (@x, @y) {
@average: ((@x + @y) / 2);
}
div {
.average (16px, 50px); //"call" the mixin
padding: @average; //use its "return" value (33px)
}
Merging rules
 The merge feature allows for aggregating values from multiple
properties
CSS output:
.myclass {
box-shadow: inset 0 0 10px #555, 0 0 20px black;
}
Less code:
.mixin() {
box-shadow+: inset 0 0 10px #555;
}
.myclass {
.mixin();
box-shadow+: 0 0 20px black;
}
Mixin libraries
3L Mixins library
animate Library of CSS3 keyframe animations
Clearless Collection of mixins
CssEffects Collection of CSS style effects
Cssowl Mixin library
cube.less Animated 3D cube using only CSS
Hexagon Generate CSS hexagons with custom size and color
LESS Elements Set of mixins
LESS Hat Mixins library
LESS-bidi Set of mixins for creating bi-directional styling
media-query-to-type Media Queries to Media Types with Less
More-Colors.less
Variables for easier color manipulation while you design in the
browser
More.less Mixins, animations, shapes and more
Oban Collection of mixins
Preboot Collection of variables and mixins. The precursor to Bootstrap
Shape.LESS Collection of mixins for various shapes
tRRtoolbelt.less Mixins and functions for common actions
Bundles
 Bundles are way to define a bunch of variables and mixins under one
namespace
Usage:
#header a {
color: orange;
#bundle > .button;
}
Definition:
#bundle {
.button {
display: block;
border: 1px solid black;
background-color: grey;
&:hover {
background-color: white;
}
}
.tab { ... }
.citation { ... }
}
Functions
 Less has a powerful set of a built-in functions and
operations.
 There are:
 Math functions: sqrt, pow, abs, sin, cos…
 String functions: escape, format, replace…
 List functions: length, extract...
 Color functions: mix, spin, lighten…
 And more…
Functions
Type checking operations
are available:
 isnumber
 isstring
 iscolor
 iskeyword
 isurl
 ispixel
 isem
 ispercentage
 isunit
 For instance this is how isnumber
works:
isnumber(#ff0); // false
isnumber(blue); // false
isnumber("string"); // false
isnumber(1234); // true
isnumber(56px); // true
isnumber(7.8%); // true
isnumber(keyword); // false
isnumber(url(...)); // false
Color operations
saturate(hsl(90%, 80%, 50%), 20%)
desaturate(hsl(90%, 80%, 50%), 20%)
lighten(hsl(90%, 80%, 50%), 20%)
darken(hsl(90%, 80%, 50%), 20%)
fade(hsl(90%, 80%, 50%), 10%)
spin(hsl(90%, 80%, 50%), 30)
greyscale(hsl(90%, 80%, 50%))
mix(#ff0000, #0000ff, 50%)
Less includes a lot of operations to make color operating quick and easy:
Color blending
multiply(#ff6600, #333333);
screen(#ff6600, #333333);
overlay(#ff6600, #333333);
softlight(#ff6600, #333333);
hardlight(#ff6600, #333333);
difference(#ff6600, #333333);
exclusion(#ff6600, #333333);
average(#ff6600, #333333);
negation(#ff6600, #333333);
You can easily blend colors in your rules with special functions:
@Import
 @import keyword allows to Import styles from other style sheets.
 @import can be used in any line of file.
@import "foo"; // foo.less is imported
@import "foo.less"; // foo.less is imported
@import "foo.php"; // foo.php imported as a less file
@import "foo.css"; // statement left in place, as-is
 Less offers several extensions to the @import to provide more flexibility
 Syntax: @import (option) "filename";
 Options:
• reference: use a Less file but do not output it
• inline: include the source file in the output but do not process it
• less: treat the file as a Less file, no matter what the file extension
• css: treat the file as a CSS file, no matter what the file extension
• once: only include the file once (this is default behavior)
• multiple: include the file multiple time
Tools & GUIs for LESS
Crunch! - Less editor for Windows and Mac.
Mixture - rapid prototyping and static site generation tool for
designers and developers
SimpLESS - minimalistic Less compiler. Just drag, drop and
compile.
Koala - cross-platform GUI application for compiling less, sass
and coffeescript.
Prepros App - free and open source app that can compile less, sass,
stylus, jade, haml and much more.
WinLess - Less compiler with a set of options
LiveReload - live editor. CoffeeScript, SASS, Less and others just
work.
Support in IDEs
 LESS is supported by all popular editors and IDE’s (natively or with
plugins help), including:
 Visual Studio
 Eclipse
 Sublime Text 2 & 3
 TextMate
 Vim
 NetBeans (built-in syntax highlighting)
 jetBrains WebStorm and PhpStorm (built-in support)
 CodeLobster (built-in syntax highlighting)
 Dreamweaver
 Notepad++ 6.x
LESS is used by:
Alternatives
 Stylus - Expressive, dynamic,
robust CSS
 SASS - CSS with superpowers
Links
lesscss.org official LESS website
https://github.com/less/less.js GitHub repo
https://www.npmjs.org/package/grunt-
contrib-less
Grunt plugin
http://winless.org/online-less-compiler Online compiler
https://github.com/Asual/lesscss-engine Java LESS port
http://www.dotlesscss.org .NET LESS port
http://crunchapp.net Crunch! editor website
http://learnboost.github.io/stylus/ Stylus website
http://sass-lang.com/ SASS website
Any questions?
1 von 30

Recomendados

CSS Preprocessors: LESS is more or look SASS-y trying von
CSS Preprocessors: LESS is more or look SASS-y tryingCSS Preprocessors: LESS is more or look SASS-y trying
CSS Preprocessors: LESS is more or look SASS-y tryingJames Cryer
1.9K views19 Folien
Syntactically awesome stylesheets (Sass) von
Syntactically awesome stylesheets (Sass)Syntactically awesome stylesheets (Sass)
Syntactically awesome stylesheets (Sass)Tahmina Khatoon
2.5K views47 Folien
Introduction to SASS von
Introduction to SASSIntroduction to SASS
Introduction to SASSJon Dean
13K views21 Folien
Compass/Sass von
Compass/SassCompass/Sass
Compass/Sassguest2409d3
817 views54 Folien
An Introduction to CSS Preprocessors (SASS & LESS) von
An Introduction to CSS Preprocessors (SASS & LESS)An Introduction to CSS Preprocessors (SASS & LESS)
An Introduction to CSS Preprocessors (SASS & LESS)Folio3 Software
1.6K views51 Folien
Sass and compass workshop von
Sass and compass workshopSass and compass workshop
Sass and compass workshopShaho Toofani
982 views171 Folien

Más contenido relacionado

Was ist angesagt?

Less css von
Less cssLess css
Less cssBill Chea
2K views12 Folien
Less vs sass von
Less vs sassLess vs sass
Less vs sassAya Edamoto
12.7K views16 Folien
SASS - Syntactically Awesome Stylesheet von
SASS - Syntactically Awesome StylesheetSASS - Syntactically Awesome Stylesheet
SASS - Syntactically Awesome StylesheetNeha Sharma
1.2K views32 Folien
Sass presentation von
Sass presentationSass presentation
Sass presentationDavin Abraham
875 views25 Folien
Css to-scss von
Css to-scssCss to-scss
Css to-scssfrontendne
1.1K views18 Folien
Sass presentation von
Sass presentationSass presentation
Sass presentationМарко Ковачевић
1.6K views11 Folien

Was ist angesagt?(19)

Less vs sass von Aya Edamoto
Less vs sassLess vs sass
Less vs sass
Aya Edamoto12.7K views
SASS - Syntactically Awesome Stylesheet von Neha Sharma
SASS - Syntactically Awesome StylesheetSASS - Syntactically Awesome Stylesheet
SASS - Syntactically Awesome Stylesheet
Neha Sharma1.2K views
Css to-scss von frontendne
Css to-scssCss to-scss
Css to-scss
frontendne1.1K views
Authoring Stylesheets with Compass & Sass von chriseppstein
Authoring Stylesheets with Compass & SassAuthoring Stylesheets with Compass & Sass
Authoring Stylesheets with Compass & Sass
chriseppstein5K views
HTML5, CSS, JavaScript Style guide and coding conventions von Knoldus Inc.
HTML5, CSS, JavaScript Style guide and coding conventionsHTML5, CSS, JavaScript Style guide and coding conventions
HTML5, CSS, JavaScript Style guide and coding conventions
Knoldus Inc.5.8K views
Bringing sexy back to CSS: SASS/SCSS, LESS and Compass von Claudina Sarahe
Bringing sexy back to CSS: SASS/SCSS, LESS and CompassBringing sexy back to CSS: SASS/SCSS, LESS and Compass
Bringing sexy back to CSS: SASS/SCSS, LESS and Compass
Claudina Sarahe3K views
SASS is more than LESS von Itai Koren
SASS is more than LESSSASS is more than LESS
SASS is more than LESS
Itai Koren1.2K views
Preprocessor presentation von Mario Noble
Preprocessor presentationPreprocessor presentation
Preprocessor presentation
Mario Noble1.3K views
Fasten RWD Development with Sass von Sven Wolfermann
Fasten RWD Development with SassFasten RWD Development with Sass
Fasten RWD Development with Sass
Sven Wolfermann5.2K views
Breaking Free from Bootstrap: Custom Responsive Grids with Sass Susy von James Steinbach
Breaking Free from Bootstrap: Custom Responsive Grids with Sass SusyBreaking Free from Bootstrap: Custom Responsive Grids with Sass Susy
Breaking Free from Bootstrap: Custom Responsive Grids with Sass Susy
James Steinbach48.1K views
Adaptive theming using compass susy grid von soovor
Adaptive theming using compass susy gridAdaptive theming using compass susy grid
Adaptive theming using compass susy grid
soovor4.7K views
CSS preprocessor: why and how von mirahman
CSS preprocessor: why and howCSS preprocessor: why and how
CSS preprocessor: why and how
mirahman1.9K views
Less(CSS Pre Processor) Introduction von rushi7567
Less(CSS Pre Processor) IntroductionLess(CSS Pre Processor) Introduction
Less(CSS Pre Processor) Introduction
rushi756758 views

Similar a Write LESS. DO more.

@Agawish creating a stunning ui with oracle adf faces, using sass von
@Agawish   creating a stunning ui with oracle adf faces, using sass@Agawish   creating a stunning ui with oracle adf faces, using sass
@Agawish creating a stunning ui with oracle adf faces, using sassAmr Gawish
2.7K views32 Folien
CSS Less framework overview, Pros and Cons von
CSS Less framework overview, Pros and ConsCSS Less framework overview, Pros and Cons
CSS Less framework overview, Pros and ConsSanjoy Kr. Paul
78 views25 Folien
Accelerated Stylesheets von
Accelerated StylesheetsAccelerated Stylesheets
Accelerated StylesheetsWynn Netherland
1.3K views147 Folien
LESS(CSS preprocessor) von
LESS(CSS preprocessor)LESS(CSS preprocessor)
LESS(CSS preprocessor)VIPIN KUMAR
696 views18 Folien
Doing More With Less von
Doing More With LessDoing More With Less
Doing More With LessDavid Engel
1.3K views37 Folien
What is LessCSS and its Detailed Explation - Xhtmlchop von
What is LessCSS and its Detailed Explation - XhtmlchopWhat is LessCSS and its Detailed Explation - Xhtmlchop
What is LessCSS and its Detailed Explation - Xhtmlchopxhtmlchop
835 views58 Folien

Similar a Write LESS. DO more.(20)

@Agawish creating a stunning ui with oracle adf faces, using sass von Amr Gawish
@Agawish   creating a stunning ui with oracle adf faces, using sass@Agawish   creating a stunning ui with oracle adf faces, using sass
@Agawish creating a stunning ui with oracle adf faces, using sass
Amr Gawish2.7K views
CSS Less framework overview, Pros and Cons von Sanjoy Kr. Paul
CSS Less framework overview, Pros and ConsCSS Less framework overview, Pros and Cons
CSS Less framework overview, Pros and Cons
Sanjoy Kr. Paul78 views
LESS(CSS preprocessor) von VIPIN KUMAR
LESS(CSS preprocessor)LESS(CSS preprocessor)
LESS(CSS preprocessor)
VIPIN KUMAR696 views
Doing More With Less von David Engel
Doing More With LessDoing More With Less
Doing More With Less
David Engel1.3K views
What is LessCSS and its Detailed Explation - Xhtmlchop von xhtmlchop
What is LessCSS and its Detailed Explation - XhtmlchopWhat is LessCSS and its Detailed Explation - Xhtmlchop
What is LessCSS and its Detailed Explation - Xhtmlchop
xhtmlchop835 views
Advanced Technology for Web Application Design von Bryce Kerley
Advanced Technology for Web Application DesignAdvanced Technology for Web Application Design
Advanced Technology for Web Application Design
Bryce Kerley728 views
LESS(CSS Pre Processor) introduction von rushi7567
LESS(CSS Pre Processor) introductionLESS(CSS Pre Processor) introduction
LESS(CSS Pre Processor) introduction
rushi7567242 views
Elegant CSS Design In Drupal: LESS vs Sass von Mediacurrent
Elegant CSS Design In Drupal: LESS vs SassElegant CSS Design In Drupal: LESS vs Sass
Elegant CSS Design In Drupal: LESS vs Sass
Mediacurrent7.7K views
CSS 開發加速指南-Sass & Compass von Lucien Lee
CSS 開發加速指南-Sass & CompassCSS 開發加速指南-Sass & Compass
CSS 開發加速指南-Sass & Compass
Lucien Lee2.5K views
CSS Methodology von Zohar Arad
CSS MethodologyCSS Methodology
CSS Methodology
Zohar Arad964 views
Advanced sass/compass von Nick Cooley
Advanced sass/compassAdvanced sass/compass
Advanced sass/compass
Nick Cooley6.1K views

Último

DSD-INT 2023 - Delft3D User Days - Welcome - Day 3 - Afternoon von
DSD-INT 2023 - Delft3D User Days - Welcome - Day 3 - AfternoonDSD-INT 2023 - Delft3D User Days - Welcome - Day 3 - Afternoon
DSD-INT 2023 - Delft3D User Days - Welcome - Day 3 - AfternoonDeltares
13 views43 Folien
Advanced API Mocking Techniques von
Advanced API Mocking TechniquesAdvanced API Mocking Techniques
Advanced API Mocking TechniquesDimpy Adhikary
19 views11 Folien
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ... von
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...Donato Onofri
711 views34 Folien
Copilot Prompting Toolkit_All Resources.pdf von
Copilot Prompting Toolkit_All Resources.pdfCopilot Prompting Toolkit_All Resources.pdf
Copilot Prompting Toolkit_All Resources.pdfRiccardo Zamana
6 views4 Folien
Software evolution understanding: Automatic extraction of software identifier... von
Software evolution understanding: Automatic extraction of software identifier...Software evolution understanding: Automatic extraction of software identifier...
Software evolution understanding: Automatic extraction of software identifier...Ra'Fat Al-Msie'deen
7 views33 Folien
MariaDB stored procedures and why they should be improved von
MariaDB stored procedures and why they should be improvedMariaDB stored procedures and why they should be improved
MariaDB stored procedures and why they should be improvedFederico Razzoli
8 views32 Folien

Último(20)

DSD-INT 2023 - Delft3D User Days - Welcome - Day 3 - Afternoon von Deltares
DSD-INT 2023 - Delft3D User Days - Welcome - Day 3 - AfternoonDSD-INT 2023 - Delft3D User Days - Welcome - Day 3 - Afternoon
DSD-INT 2023 - Delft3D User Days - Welcome - Day 3 - Afternoon
Deltares13 views
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ... von Donato Onofri
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...
Donato Onofri711 views
Copilot Prompting Toolkit_All Resources.pdf von Riccardo Zamana
Copilot Prompting Toolkit_All Resources.pdfCopilot Prompting Toolkit_All Resources.pdf
Copilot Prompting Toolkit_All Resources.pdf
Riccardo Zamana6 views
Software evolution understanding: Automatic extraction of software identifier... von Ra'Fat Al-Msie'deen
Software evolution understanding: Automatic extraction of software identifier...Software evolution understanding: Automatic extraction of software identifier...
Software evolution understanding: Automatic extraction of software identifier...
MariaDB stored procedures and why they should be improved von Federico Razzoli
MariaDB stored procedures and why they should be improvedMariaDB stored procedures and why they should be improved
MariaDB stored procedures and why they should be improved
Tridens DevOps von Tridens
Tridens DevOpsTridens DevOps
Tridens DevOps
Tridens9 views
Mark Simpson - UKOUG23 - Refactoring Monolithic Oracle Database Applications ... von marksimpsongw
Mark Simpson - UKOUG23 - Refactoring Monolithic Oracle Database Applications ...Mark Simpson - UKOUG23 - Refactoring Monolithic Oracle Database Applications ...
Mark Simpson - UKOUG23 - Refactoring Monolithic Oracle Database Applications ...
marksimpsongw76 views
Geospatial Synergy: Amplifying Efficiency with FME & Esri ft. Peak Guest Spea... von Safe Software
Geospatial Synergy: Amplifying Efficiency with FME & Esri ft. Peak Guest Spea...Geospatial Synergy: Amplifying Efficiency with FME & Esri ft. Peak Guest Spea...
Geospatial Synergy: Amplifying Efficiency with FME & Esri ft. Peak Guest Spea...
Safe Software412 views
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI... von Marc Müller
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...
Marc Müller36 views
Citi TechTalk Session 2: Kafka Deep Dive von confluent
Citi TechTalk Session 2: Kafka Deep DiveCiti TechTalk Session 2: Kafka Deep Dive
Citi TechTalk Session 2: Kafka Deep Dive
confluent17 views
DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J... von Deltares
DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J...DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J...
DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J...
Deltares9 views
Consulting for Data Monetization Maximizing the Profit Potential of Your Data... von Flexsin
Consulting for Data Monetization Maximizing the Profit Potential of Your Data...Consulting for Data Monetization Maximizing the Profit Potential of Your Data...
Consulting for Data Monetization Maximizing the Profit Potential of Your Data...
Flexsin 15 views
DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -... von Deltares
DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -...DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -...
DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -...
Deltares6 views
DSD-INT 2023 SFINCS Modelling in the U.S. Pacific Northwest - Parker von Deltares
DSD-INT 2023 SFINCS Modelling in the U.S. Pacific Northwest - ParkerDSD-INT 2023 SFINCS Modelling in the U.S. Pacific Northwest - Parker
DSD-INT 2023 SFINCS Modelling in the U.S. Pacific Northwest - Parker
Deltares9 views
Software testing company in India.pptx von SakshiPatel82
Software testing company in India.pptxSoftware testing company in India.pptx
Software testing company in India.pptx
SakshiPatel827 views
DSD-INT 2023 HydroMT model building and river-coast coupling in Python - Bove... von Deltares
DSD-INT 2023 HydroMT model building and river-coast coupling in Python - Bove...DSD-INT 2023 HydroMT model building and river-coast coupling in Python - Bove...
DSD-INT 2023 HydroMT model building and river-coast coupling in Python - Bove...
Deltares17 views

Write LESS. DO more.

  • 2. What is LESS?  Less – preprocessor language that extends usual CSS to make it more readable and maintainable.  Outputs the code to pure CSS  Adds semantic and structure to stylesheets  Makes coding slightly faster  …and fun (most of the time)
  • 3. Example Less code: @base: #f938ab; @text: saturate(@base, 5%); .shadow(@style, @c: #f5f5f5) { -webkit-box-shadow: @style @c; box-shadow: @style @c; border: 1px solid @c; } .box { color: @text; div { .shadow(0 0 5px, @base) } } CSS output: .box { color: #fe33ac; } .box div { -webkit-box-shadow: 0 0 5px #fdcdea; box-shadow: 0 0 5px #fdcdea); border: 1px solid #fdcdea); }
  • 4. Some history  Less was created in 2009 by Alexis Sellier, more commonly known as @cloudhead. Originally written in Ruby, it was then ported to JavaScript.  In May 2012 Alexis relinquished control and development over to a core team of contributors who now manage, fix and extend the language.  Less is maintained by a group of invaluable core contributors, with the massive support and involvement of our community.
  • 5. Installation & usage  Less can be used on command line as Node package (make sure you have NodeJS installed): npm install less –g  After successful installation you can use it next ways:  $ lessc styles.less - this will output the compiled CSS to stdout  $ lessc styles.less > styles.css - will output CSS to file styles.css  $ lessc styles.less > styles.css –x - will output minified CSS
  • 6. Installation & usage  Also it’s possible to use LESS as a Grunt task: npm install grunt-contrib-less --save-dev  Gruntfile: less: { development: { options: { paths: ["assets/css"] }, files: { "path/to/result.css": "path/to/source.less" } } grunt.loadNpmTasks('grunt-contrib-less');
  • 7. Installation & usage  Include it a script file for the browser (not recommended for production).  Make sure you include your stylesheets before the script.  You can add some options for convenient debugging. <script> less = { env: "development", async: false, fileAsync: false, poll: 1000, functions: {}, relativeUrls: false, rootpath: ":/a.com/“ }; </script> <script src="less.js"></script> <script>less.watch();</script> <!—This enables live browser reload-->
  • 8. Nested rules  Less allows you to nest selectors one into another just the same as they are placed in HTML: Less code: #header { color: black; .navigation { font-size: 12px; } .logo { width: 300px; } } CSS output: #header { color: black; } #header .navigation { font-size: 12px; } #header .logo { width: 300px; }
  • 9. Variables  Define variables and refer to them in your rules.  When defining a variable twice, the last definition of the variable is used, searching from the current scope upwards (scopes work just like in JavaScript) @var: 0; .class1 { @var: 1; .class { @var: 2; three: @var; @var: 3; } one: @var; } @nice-blue: #5B83AD; @light-blue: @nice-blue + #111; #header { color: @light-blue; border-color: @nice-blue; }
  • 10. Arithmetic  Any number, color or variable in Less can be operated: @base: 5%; @filler: @base * 2; @other: @base + @filler; color: #888 / 4; background-color: @base-color + #111; height: 100% / 2 + @filler;  LESS understands units well: @var: 1px + 5; //6px
  • 11. Mixins  Mixins are a way of including ("mixing in") a bunch of properties from one rule-set into another rule-set Definition: .bordered { border-top: dotted 1px black; border-bottom: solid 2px black; } .no-decoration { text-decoration: none; } Usage: #menu a { color: #111; .no-decoration; } .post a { color: red; .bordered; }
  • 12. Mixins without output  Mixin can be created without output to result style: CSS output: .my-mixin { color: black; } .class { color: black; background-color: white; } Less code: .my-mixin { color: black; } .my-other-mixin() { background-color: white; } .class { .my-mixin; .my-other-mixin; }
  • 13. This!  & symbol represents the current parent selector (such as this keyword in JavaScript) CSS output: button :hover { border: 1px solid red; } Less code: .my-hover-mixin() { &:hover { border: 1px solid red; } } button { .my-hover-mixin(); }
  • 14. Parametric mixins  Pass parameters to mixins to make them more versatile.  It’s possible to declare default values of parameters in mixin definition. Definition: .border-radius(@radius: 10px) { -webkit-border-radius: @radius; -moz-border-radius: @radius; border-radius: @radius; } Usage: #header { .border-radius(4px); } .button { .border-radius(6px); }
  • 15. Mixin guards  Guards in Less are useful for conditional declaration of mixins  Guards allows you to check value of a parameter as well as its type .mixin (@a) when (lightness(@a) >= 50%) { background-color: black; } .mixin (@a) when (lightness(@a) < 50%) { background-color: white; } .mixin (@a) { color: @a; } .another-mixin (@a; @b: 0) when (isnumber(@b)) { ... } .another-mixin (@a; @b: black) when (iscolor(@b)) { ... }
  • 16. Return variables  All variables defined in a mixin are visible and can be used in caller's scope. This allows to create mixins that can be used almost like a functions .average (@x, @y) { @average: ((@x + @y) / 2); } div { .average (16px, 50px); //"call" the mixin padding: @average; //use its "return" value (33px) }
  • 17. Merging rules  The merge feature allows for aggregating values from multiple properties CSS output: .myclass { box-shadow: inset 0 0 10px #555, 0 0 20px black; } Less code: .mixin() { box-shadow+: inset 0 0 10px #555; } .myclass { .mixin(); box-shadow+: 0 0 20px black; }
  • 18. Mixin libraries 3L Mixins library animate Library of CSS3 keyframe animations Clearless Collection of mixins CssEffects Collection of CSS style effects Cssowl Mixin library cube.less Animated 3D cube using only CSS Hexagon Generate CSS hexagons with custom size and color LESS Elements Set of mixins LESS Hat Mixins library LESS-bidi Set of mixins for creating bi-directional styling media-query-to-type Media Queries to Media Types with Less More-Colors.less Variables for easier color manipulation while you design in the browser More.less Mixins, animations, shapes and more Oban Collection of mixins Preboot Collection of variables and mixins. The precursor to Bootstrap Shape.LESS Collection of mixins for various shapes tRRtoolbelt.less Mixins and functions for common actions
  • 19. Bundles  Bundles are way to define a bunch of variables and mixins under one namespace Usage: #header a { color: orange; #bundle > .button; } Definition: #bundle { .button { display: block; border: 1px solid black; background-color: grey; &:hover { background-color: white; } } .tab { ... } .citation { ... } }
  • 20. Functions  Less has a powerful set of a built-in functions and operations.  There are:  Math functions: sqrt, pow, abs, sin, cos…  String functions: escape, format, replace…  List functions: length, extract...  Color functions: mix, spin, lighten…  And more…
  • 21. Functions Type checking operations are available:  isnumber  isstring  iscolor  iskeyword  isurl  ispixel  isem  ispercentage  isunit  For instance this is how isnumber works: isnumber(#ff0); // false isnumber(blue); // false isnumber("string"); // false isnumber(1234); // true isnumber(56px); // true isnumber(7.8%); // true isnumber(keyword); // false isnumber(url(...)); // false
  • 22. Color operations saturate(hsl(90%, 80%, 50%), 20%) desaturate(hsl(90%, 80%, 50%), 20%) lighten(hsl(90%, 80%, 50%), 20%) darken(hsl(90%, 80%, 50%), 20%) fade(hsl(90%, 80%, 50%), 10%) spin(hsl(90%, 80%, 50%), 30) greyscale(hsl(90%, 80%, 50%)) mix(#ff0000, #0000ff, 50%) Less includes a lot of operations to make color operating quick and easy:
  • 23. Color blending multiply(#ff6600, #333333); screen(#ff6600, #333333); overlay(#ff6600, #333333); softlight(#ff6600, #333333); hardlight(#ff6600, #333333); difference(#ff6600, #333333); exclusion(#ff6600, #333333); average(#ff6600, #333333); negation(#ff6600, #333333); You can easily blend colors in your rules with special functions:
  • 24. @Import  @import keyword allows to Import styles from other style sheets.  @import can be used in any line of file. @import "foo"; // foo.less is imported @import "foo.less"; // foo.less is imported @import "foo.php"; // foo.php imported as a less file @import "foo.css"; // statement left in place, as-is  Less offers several extensions to the @import to provide more flexibility  Syntax: @import (option) "filename";  Options: • reference: use a Less file but do not output it • inline: include the source file in the output but do not process it • less: treat the file as a Less file, no matter what the file extension • css: treat the file as a CSS file, no matter what the file extension • once: only include the file once (this is default behavior) • multiple: include the file multiple time
  • 25. Tools & GUIs for LESS Crunch! - Less editor for Windows and Mac. Mixture - rapid prototyping and static site generation tool for designers and developers SimpLESS - minimalistic Less compiler. Just drag, drop and compile. Koala - cross-platform GUI application for compiling less, sass and coffeescript. Prepros App - free and open source app that can compile less, sass, stylus, jade, haml and much more. WinLess - Less compiler with a set of options LiveReload - live editor. CoffeeScript, SASS, Less and others just work.
  • 26. Support in IDEs  LESS is supported by all popular editors and IDE’s (natively or with plugins help), including:  Visual Studio  Eclipse  Sublime Text 2 & 3  TextMate  Vim  NetBeans (built-in syntax highlighting)  jetBrains WebStorm and PhpStorm (built-in support)  CodeLobster (built-in syntax highlighting)  Dreamweaver  Notepad++ 6.x
  • 28. Alternatives  Stylus - Expressive, dynamic, robust CSS  SASS - CSS with superpowers
  • 29. Links lesscss.org official LESS website https://github.com/less/less.js GitHub repo https://www.npmjs.org/package/grunt- contrib-less Grunt plugin http://winless.org/online-less-compiler Online compiler https://github.com/Asual/lesscss-engine Java LESS port http://www.dotlesscss.org .NET LESS port http://crunchapp.net Crunch! editor website http://learnboost.github.io/stylus/ Stylus website http://sass-lang.com/ SASS website