SlideShare uma empresa Scribd logo
1 de 25
Baixar para ler offline
{less}
It's CSS, with just a little more.
LESS Framework
Overview, pros and cons..
Sanjoy K. Paul
Lead Application Developer, DevOps
SanjoyPaul.com | hello@skpaul.me | +880-1511-927992
What is Less Framework?
Less (Leaner Style Sheets) is a backwards-compatible language extension for CSS.
- Less.js, the JavaScript tool that converts your Less styles to CSS styles.
- Less looks just like CSS, so it is easy to learn.
- Less only makes a few convenient additions to the CSS language, which is one of the reasons it can be learned
so quickly.
- Cleaner and more readable code can be written in an organized way.
- We can define styles and it can be reused throughout the code.
- LESS is an agile tool that sorts out the problem of code redundancy.
LESS was designed by Alexis Sellier in 2009 and published as an open-source. The first version of LESS was written in
Ruby; in the later versions, the use of Ruby was replaced by JavaScript.
What does Less add to CSS?
We will go through a quick overview of features.
- Comments
- Importing
- Variables
- Mixins
- Nesting
- Nested At-Rules and Bubbling
- Operations
- Escaping
- Namespaces and Accessors
- Maps
- Scope
Comments in Less
Both block-style and inline comments may be used
/* One heck of a block
* style comment! */
@var: red;
// Get in line!
@var: white;
Importing in Less
Importing works pretty much as expected. You can import a .less file, and all the variables in it will be available. The
extension is optionally specified for .less files.
@import "library"; // library.less
@import "typo.css";
Variables in Less
Variables are pretty self-explanatory, these are same as in other programming languages (i.e.: JavaScript/C/C++/Java).
@width: 10px;
@height: @width + 10px;
#header {
width: @width;
height: @height;
}
:root{
--width: 10px;
--height: var(--width) +
10px;
}
#header {
width: var(--width);
height: var(--height);
}
Mixins in Less
A way of including ("mixing in") a bunch of properties from one rule-set into another rule-set.
.bordered {
border-top: dotted 1px black;
border-bottom: solid 2px black;
}
#menu a {
color: #111;
.bordered();
}
.post a {
color: red;
.bordered();
}
.bordered {
border-top: dotted 1px black;
border-bottom: solid 2px black;
}
Parametric Mixins:
.border(@width; @style; @color) {
border: @width @style @color;
}
.myheader {
.border(2px; dashed; green);
}
Functions, Guards, Passing Rulesets
Nesting in Less
Less gives you the ability to use nesting instead of, or in combination with cascading.
CSS Code
#header {
color: black;
}
#header .navigation {
font-size: 12px;
}
#header .logo {
width: 300px;
}
LESS Code
#header {
color: black;
.navigation {
font-size: 12px;
}
.logo {
width: 300px;
}
}
Code is more concise, and mimics the structure of the HTML.
Nesting in Less
We can also bundle pseudo-selectors with our mixins using this method. Here's the classic clearfix hack, rewritten as a
mixin (& represents the current selector parent):
.clearfix {
display: block;
zoom: 1;
&:after {
content: " ";
display: block;
font-size: 0;
height: 0;
clear: both;
visibility: hidden;
}
}
a {
color: blue;
&:hover {
color: green;
}
}
a {
color: blue;
}
a:hover {
color: green;
}
Nested At-Rules and Bubbling in Less
At-rules such as @media or @supports can be nested in the same way as selectors. The at-rule is placed on top and
relative order against other elements inside the same ruleset remains unchanged.
.component {
width: 300px;
@media (min-width: 768px) {
width: 600px;
@media (min-resolution: 192dpi) {
background-image : url(/img/retina2x.png );
}
}
@media (min-width: 1280px) {
width: 800px;
}
}
.component {
width: 300px;
}
@media (min-width: 768px) {
.component {
width: 600px;
}
}
@media (min-width: 768px) and (min-resolution: 192dpi) {
.component {
background-image : url(/img/retina2x.png );
}
}
@media (min-width: 1280px) {
.component {
width: 800px;
}
}
Operations in Less
Arithmetical operations (+, -, *, /) can operate on any number, color or variable.
- If it is possible, mathematical operations take units into account and convert numbers before adding,
subtracting or comparing them.
- The result has leftmost explicitly stated unit type.
- If the conversion is impossible or not meaningful, units are ignored.
- Multiplication and division do not convert numbers. It would not be meaningful in most cases - a length
multiplied by a length gives an area and css does not support specifying areas.
- Less operates on numbers as they are and assign explicitly stated unit type to the result.
- Less allows us to do arithmetical operation on colors (#224488 / 2 = #112244)
Let’s see some example..
Operations in Less
Example: Impossible conversion: px to cm or rad to %.
// numbers are converted into the same units
@conversion-1: 5cm + 10mm; // result is 6cm
@conversion-2: 2 - 3cm - 5mm; // result is -1.5cm
// conversion is impossible
@incompatible-units: 2 + 5px - 3cm; // result is 4px
// example with variables
@base: 5%;
@filler: @base * 2; // result is 10%
@other: @base + @filler; // result is 15%
Example: Multiplication and division do not convert numbers.
@base: 2cm * 3mm; // result is 6cm
Example: Arithmetic on colors
@color: #224488 / 2; //results in #112244
background-color
: #112244 + #111; // result is #223355
Example: Colors functions
saturate(hsl(90, 80%, 50%), 20%) =>#80ff00 // hsl(90, 100%, 50%)
lighten(hsl(90, 80%, 50%), 20%) => #b3f075 // hsl(90, 80%, 70%)
darken(hsl(90, 80%, 50%), 20%) => #4d8a0f // hsl(90, 80%, 30%)
fade(hsl(90, 90%, 50%), 10%) => rgba(128, 242, 13, 0.1) //hsla(90,
90%, 50%, 0.1)
Operations (calc() exception) in Less
calc() function does not evaluate math expressions for CSS compatibility, but it evaluates variables and math in nested
functions.
@var: 50vh/2;
width: calc(50% + (@var - 20px)); // output is calc(50% + (25vh - 20px))
Functions in Less
Less provides a variety of functions which transform colors, manipulate strings and do maths
@base: #f04615;
@width: 0.5;
.class {
width: percentage(@width); // returns `50%`
color: saturate(@base, 5%);
background-color
: spin(lighten(@base, 25%), 8);
}
Using them is pretty straightforward.
This example uses
percentage to convert 0.5 to 50%,
increases the saturation of a base color by 5%
and then sets the background color to one that is lightened
by 25% and spun by 8 degrees.
Namespaces and Accessors in Less
Sometimes, you may want to group your mixins, for organizational purposes, or just to offer some encapsulation. You
can do this pretty intuitively in Less.
Example: if we want to bundle some mixins and variables under
#bundle, for later reuse or distributing.
#bundle() {
.button {
display: block;
border: 1px solid black;
background-color
: grey;
&:hover {
background-color
: white;
}
}
.tab { ... }
.citation { ... }
}
Now if we want to mixin the .button class in our #header a, we
can do
#header a {
color: orange;
#bundle.button(); // can also be written as
#bundle > .button
}
Note: append () to your namespace (e.g. #bundle()) if you don't
want it to appear in your CSS output i.e. #bundle .tab.
Escaping in Less
Escaping allows you to use any arbitrary string as property or variable value. Anything inside ~"anything" or ~'anything'
is used as is with no changes except interpolation.
@min768: ~"(min-width: 768px)"
;
.element {
@media @min768 {
font-size: 1.2rem;
}
}
@media (min-width: 768px) {
.element {
font-size: 1.2rem;
}
}
In Less 3.5, you can simply write. In 3.5+, many cases previously requiring "quote-escaping" are not needed.
@min768: (min-width: 768px);
.element {
@media @min768 {
font-size: 1.2rem;
}
}
Maps in Less
We can also use mixins and rulesets as maps of values
#colors() {
primary: blue;
secondary: green;
}
.button {
color: #colors[primary];
border: 1px solid #colors[secondary];
}
.button {
color: blue;
border: 1px solid green;
}
Scope in Less
Scope in Less is very similar to that of CSS. Variables and mixins are first looked for locally, and if they aren't found, it's
inherited from the "parent" scope.
@var: red;
#page {
@var: white;
#header {
color: @var; // white
}
}
@var: red;
#page {
#header {
color: @var; // white
}
@var: white;
}
Installing, configuring and usages of Less
- Command Line Usag
- https://lesscss.org/usage/#command-line-usage
- Browser Usage
- https://lesscss.org/usage/#using-less-in-the-browser
Supports:
- Less.js supports all modern browsers (recent versions of Chrome, Firefox, Safari, IE11+, and Edge).
- It is possible to use Less on the client side in production, please be aware that there are performance implications for
doing so (although the latest releases of Less are quite a bit faster).
- Sometimes cosmetic issues can occur if a JavaScript error occurs. This is a trade off of flexibility vs. speed.
- For the fastest performance possible for a static web site,
- We recommend compiling Less on the server side.
Installing, configuring and usages of Less
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>
Need to keep in mind:
- Make sure you include your stylesheets before the script.
- When you link more than one .less stylesheet each of them is compiled independently. So any variables, mixins or namespaces you
define in a stylesheet are not accessible in any other.
- Due to the same origin policy of browsers, loading external resources requires enabling CORS
Installing, configuring and usages of Less
You can set options either programmatically, by setting them on a less object before the script tag - this then affects all initial link tags and
programmatic usage of less.
<script>
less = {
env: "development",
async: false,
fileAsync: false,
poll: 1000,
functions: {},
dumpLineNumbers
: "comments",
relativeUrls: false,
rootpath: ":/a.com/"
};
</script>
<script src="less.js"></script>
The other way is to specify the options on the script tag, e.g.
<script>
less = {
env: "development"
};
</script>
<script src="less.js" data-env="development"></script>
Or for brevity they can be set as attributes on the script and link tags
<script src="less.js" data-poll ="1000" data-relative-urls ="false"></script>
<link data-dump-line-numbers ="all" data-global-vars ='{ "myvar": "#ddffee", "mystr": ""quoted"" }' rel="stylesheet/less"
type="text/css" href="less/styles.less" >
Pros and Cons of Less
???
Cons:
- The learning curve
- Could inherit mistakes of framework
developer
- Could lead to a lack of understanding the
underlying css
- Bloated code
- Might restrict you as you conform to the
framework
- Lack of semantic code
Pros:
- Increased productivity
- Standardized codebase
- Makes it easier to work with a team
- Provides a more organized approach to
css
- Publicly released frameworks are
improved by the community
- Fewer mistakes
- Cross browser reliability
- Can be a learning tool
Would you like to learn more about Less?
- Overview: http://lesscss.org/
- Usages: https://lesscss.org/usage/#using-less-in-the-browser
- Functions: https://lesscss.org/functions/
- Features: https://lesscss.org/features/
- Tools: https://lesscss.org/tools/
- Editors and Editor Plugins: https://lesscss.org/tools/#editors-and-plugins
- Contributing?: https://lesscss.org/usage/#developing-less
- More: https://www.tutorialspoint.com/less/index.htm
Question?
Sanjoy K. Paul
Lead Application Developer | Software Architect | DevOps | Trainer
www.SanjoyPaul.com | skpaul@DevsStation.com | +880-1511-927992

Mais conteúdo relacionado

Mais procurados

Web Design Course: CSS lecture 2
Web Design Course: CSS  lecture 2Web Design Course: CSS  lecture 2
Web Design Course: CSS lecture 2Gheyath M. Othman
 
Compass, Sass, and the Enlightened CSS Developer
Compass, Sass, and the Enlightened CSS DeveloperCompass, Sass, and the Enlightened CSS Developer
Compass, Sass, and the Enlightened CSS DeveloperWynn Netherland
 
Making Sense of Twig
Making Sense of TwigMaking Sense of Twig
Making Sense of TwigBrandon Kelly
 
Web Engineering - Basic CSS Properties
Web Engineering - Basic CSS PropertiesWeb Engineering - Basic CSS Properties
Web Engineering - Basic CSS PropertiesNosheen Qamar
 
Web Design Course: CSS lecture 4
Web Design Course: CSS  lecture 4Web Design Course: CSS  lecture 4
Web Design Course: CSS lecture 4Gheyath M. Othman
 
Web Design Course: CSS lecture 3
Web Design Course: CSS lecture 3Web Design Course: CSS lecture 3
Web Design Course: CSS lecture 3Gheyath M. Othman
 
Css3 and gwt in perfect harmony
Css3 and gwt in perfect harmonyCss3 and gwt in perfect harmony
Css3 and gwt in perfect harmonyjdramaix
 
CSS Walktrough Internship Course
CSS Walktrough Internship CourseCSS Walktrough Internship Course
CSS Walktrough Internship CourseZoltan Iszlai
 
ID01 Week 3
ID01 Week 3ID01 Week 3
ID01 Week 3mkontopo
 
P H P Part I I, By Kian
P H P  Part  I I,  By  KianP H P  Part  I I,  By  Kian
P H P Part I I, By Kianphelios
 
CSS3 For WebKit: iPadDevCamp Presentation
CSS3 For WebKit: iPadDevCamp PresentationCSS3 For WebKit: iPadDevCamp Presentation
CSS3 For WebKit: iPadDevCamp PresentationEstelle Weyl
 
CSS3 Implementable Features
CSS3 Implementable FeaturesCSS3 Implementable Features
CSS3 Implementable FeaturesEstelle Weyl
 
Web Design Course: CSS lecture 1
Web Design Course: CSS lecture 1Web Design Course: CSS lecture 1
Web Design Course: CSS lecture 1Gheyath M. Othman
 
ID01 / W01
ID01 / W01ID01 / W01
ID01 / W01mkontopo
 

Mais procurados (20)

Less & Sass
Less & SassLess & Sass
Less & Sass
 
Do more with {less}
Do more with {less}Do more with {less}
Do more with {less}
 
basics of css
basics of cssbasics of css
basics of css
 
Web Design Course: CSS lecture 2
Web Design Course: CSS  lecture 2Web Design Course: CSS  lecture 2
Web Design Course: CSS lecture 2
 
Compass, Sass, and the Enlightened CSS Developer
Compass, Sass, and the Enlightened CSS DeveloperCompass, Sass, and the Enlightened CSS Developer
Compass, Sass, and the Enlightened CSS Developer
 
Ruby on Rails
Ruby on RailsRuby on Rails
Ruby on Rails
 
Css web side
Css web sideCss web side
Css web side
 
Making Sense of Twig
Making Sense of TwigMaking Sense of Twig
Making Sense of Twig
 
Web Engineering - Basic CSS Properties
Web Engineering - Basic CSS PropertiesWeb Engineering - Basic CSS Properties
Web Engineering - Basic CSS Properties
 
Web Design Course: CSS lecture 4
Web Design Course: CSS  lecture 4Web Design Course: CSS  lecture 4
Web Design Course: CSS lecture 4
 
Web Design Course: CSS lecture 3
Web Design Course: CSS lecture 3Web Design Course: CSS lecture 3
Web Design Course: CSS lecture 3
 
Css3 and gwt in perfect harmony
Css3 and gwt in perfect harmonyCss3 and gwt in perfect harmony
Css3 and gwt in perfect harmony
 
CSS Walktrough Internship Course
CSS Walktrough Internship CourseCSS Walktrough Internship Course
CSS Walktrough Internship Course
 
ID01 Week 3
ID01 Week 3ID01 Week 3
ID01 Week 3
 
P H P Part I I, By Kian
P H P  Part  I I,  By  KianP H P  Part  I I,  By  Kian
P H P Part I I, By Kian
 
Ppt ch05
Ppt ch05Ppt ch05
Ppt ch05
 
CSS3 For WebKit: iPadDevCamp Presentation
CSS3 For WebKit: iPadDevCamp PresentationCSS3 For WebKit: iPadDevCamp Presentation
CSS3 For WebKit: iPadDevCamp Presentation
 
CSS3 Implementable Features
CSS3 Implementable FeaturesCSS3 Implementable Features
CSS3 Implementable Features
 
Web Design Course: CSS lecture 1
Web Design Course: CSS lecture 1Web Design Course: CSS lecture 1
Web Design Course: CSS lecture 1
 
ID01 / W01
ID01 / W01ID01 / W01
ID01 / W01
 

Semelhante a CSS Less framework overview, Pros and Cons

Write LESS. DO more.
Write LESS. DO more.Write LESS. DO more.
Write LESS. DO more.Eugene Nor
 
@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
@Agawish creating a stunning ui with oracle adf faces, using sassAmr Gawish
 
Preprocessor presentation
Preprocessor presentationPreprocessor presentation
Preprocessor presentationMario Noble
 
SASS is more than LESS
SASS is more than LESSSASS is more than LESS
SASS is more than LESSItai Koren
 
Less(CSS Pre Processor) Introduction
Less(CSS Pre Processor) IntroductionLess(CSS Pre Processor) Introduction
Less(CSS Pre Processor) Introductionrushi7567
 
LESS(CSS Pre Processor) introduction
LESS(CSS Pre Processor) introductionLESS(CSS Pre Processor) introduction
LESS(CSS Pre Processor) introductionrushi7567
 
SASS, Compass, Gulp, Greensock
SASS, Compass, Gulp, GreensockSASS, Compass, Gulp, Greensock
SASS, Compass, Gulp, GreensockMarco Pinheiro
 
Big Design Conference: CSS3
Big Design Conference: CSS3 Big Design Conference: CSS3
Big Design Conference: CSS3 Wynn Netherland
 
Fasten RWD Development with Sass
Fasten RWD Development with SassFasten RWD Development with Sass
Fasten RWD Development with SassSven Wolfermann
 
LESS : The dynamic stylesheet language
LESS : The dynamic stylesheet languageLESS : The dynamic stylesheet language
LESS : The dynamic stylesheet languageKatsunori Tanaka
 
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 filesDinu Suman
 
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)Folio3 Software
 
Sass & Compass (Barcamp Stuttgart 2012)
Sass & Compass (Barcamp Stuttgart 2012)Sass & Compass (Barcamp Stuttgart 2012)
Sass & Compass (Barcamp Stuttgart 2012)emrox
 
Less css framework
Less css frameworkLess css framework
Less css frameworkManisha Bano
 
Css3 and gwt in perfect harmony
Css3 and gwt in perfect harmonyCss3 and gwt in perfect harmony
Css3 and gwt in perfect harmonyArcbees
 

Semelhante a CSS Less framework overview, Pros and Cons (20)

Write LESS. DO more.
Write LESS. DO more.Write LESS. DO more.
Write LESS. DO more.
 
Accelerated Stylesheets
Accelerated StylesheetsAccelerated Stylesheets
Accelerated Stylesheets
 
@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
@Agawish creating a stunning ui with oracle adf faces, using sass
 
Preprocessor presentation
Preprocessor presentationPreprocessor presentation
Preprocessor presentation
 
SASS is more than LESS
SASS is more than LESSSASS is more than LESS
SASS is more than LESS
 
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
 
CSS Extenders
CSS ExtendersCSS Extenders
CSS Extenders
 
Less css
Less cssLess css
Less css
 
SASS, Compass, Gulp, Greensock
SASS, Compass, Gulp, GreensockSASS, Compass, Gulp, Greensock
SASS, Compass, Gulp, Greensock
 
Why less?
Why less?Why less?
Why less?
 
Sass Essentials
Sass EssentialsSass Essentials
Sass Essentials
 
Big Design Conference: CSS3
Big Design Conference: CSS3 Big Design Conference: CSS3
Big Design Conference: CSS3
 
Fasten RWD Development with Sass
Fasten RWD Development with SassFasten RWD Development with Sass
Fasten RWD Development with Sass
 
LESS : The dynamic stylesheet language
LESS : The dynamic stylesheet languageLESS : The dynamic stylesheet language
LESS : The dynamic stylesheet language
 
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
 
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)
 
Sass & Compass (Barcamp Stuttgart 2012)
Sass & Compass (Barcamp Stuttgart 2012)Sass & Compass (Barcamp Stuttgart 2012)
Sass & Compass (Barcamp Stuttgart 2012)
 
Less css framework
Less css frameworkLess css framework
Less css framework
 
Css3 and gwt in perfect harmony
Css3 and gwt in perfect harmonyCss3 and gwt in perfect harmony
Css3 and gwt in perfect harmony
 

Último

How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 

Último (20)

How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 

CSS Less framework overview, Pros and Cons

  • 1. {less} It's CSS, with just a little more.
  • 2. LESS Framework Overview, pros and cons.. Sanjoy K. Paul Lead Application Developer, DevOps SanjoyPaul.com | hello@skpaul.me | +880-1511-927992
  • 3. What is Less Framework? Less (Leaner Style Sheets) is a backwards-compatible language extension for CSS. - Less.js, the JavaScript tool that converts your Less styles to CSS styles. - Less looks just like CSS, so it is easy to learn. - Less only makes a few convenient additions to the CSS language, which is one of the reasons it can be learned so quickly. - Cleaner and more readable code can be written in an organized way. - We can define styles and it can be reused throughout the code. - LESS is an agile tool that sorts out the problem of code redundancy. LESS was designed by Alexis Sellier in 2009 and published as an open-source. The first version of LESS was written in Ruby; in the later versions, the use of Ruby was replaced by JavaScript.
  • 4. What does Less add to CSS? We will go through a quick overview of features. - Comments - Importing - Variables - Mixins - Nesting - Nested At-Rules and Bubbling - Operations - Escaping - Namespaces and Accessors - Maps - Scope
  • 5. Comments in Less Both block-style and inline comments may be used /* One heck of a block * style comment! */ @var: red; // Get in line! @var: white;
  • 6. Importing in Less Importing works pretty much as expected. You can import a .less file, and all the variables in it will be available. The extension is optionally specified for .less files. @import "library"; // library.less @import "typo.css";
  • 7. Variables in Less Variables are pretty self-explanatory, these are same as in other programming languages (i.e.: JavaScript/C/C++/Java). @width: 10px; @height: @width + 10px; #header { width: @width; height: @height; } :root{ --width: 10px; --height: var(--width) + 10px; } #header { width: var(--width); height: var(--height); }
  • 8. Mixins in Less A way of including ("mixing in") a bunch of properties from one rule-set into another rule-set. .bordered { border-top: dotted 1px black; border-bottom: solid 2px black; } #menu a { color: #111; .bordered(); } .post a { color: red; .bordered(); } .bordered { border-top: dotted 1px black; border-bottom: solid 2px black; } Parametric Mixins: .border(@width; @style; @color) { border: @width @style @color; } .myheader { .border(2px; dashed; green); } Functions, Guards, Passing Rulesets
  • 9. Nesting in Less Less gives you the ability to use nesting instead of, or in combination with cascading. CSS Code #header { color: black; } #header .navigation { font-size: 12px; } #header .logo { width: 300px; } LESS Code #header { color: black; .navigation { font-size: 12px; } .logo { width: 300px; } } Code is more concise, and mimics the structure of the HTML.
  • 10. Nesting in Less We can also bundle pseudo-selectors with our mixins using this method. Here's the classic clearfix hack, rewritten as a mixin (& represents the current selector parent): .clearfix { display: block; zoom: 1; &:after { content: " "; display: block; font-size: 0; height: 0; clear: both; visibility: hidden; } } a { color: blue; &:hover { color: green; } } a { color: blue; } a:hover { color: green; }
  • 11. Nested At-Rules and Bubbling in Less At-rules such as @media or @supports can be nested in the same way as selectors. The at-rule is placed on top and relative order against other elements inside the same ruleset remains unchanged. .component { width: 300px; @media (min-width: 768px) { width: 600px; @media (min-resolution: 192dpi) { background-image : url(/img/retina2x.png ); } } @media (min-width: 1280px) { width: 800px; } } .component { width: 300px; } @media (min-width: 768px) { .component { width: 600px; } } @media (min-width: 768px) and (min-resolution: 192dpi) { .component { background-image : url(/img/retina2x.png ); } } @media (min-width: 1280px) { .component { width: 800px; } }
  • 12. Operations in Less Arithmetical operations (+, -, *, /) can operate on any number, color or variable. - If it is possible, mathematical operations take units into account and convert numbers before adding, subtracting or comparing them. - The result has leftmost explicitly stated unit type. - If the conversion is impossible or not meaningful, units are ignored. - Multiplication and division do not convert numbers. It would not be meaningful in most cases - a length multiplied by a length gives an area and css does not support specifying areas. - Less operates on numbers as they are and assign explicitly stated unit type to the result. - Less allows us to do arithmetical operation on colors (#224488 / 2 = #112244) Let’s see some example..
  • 13. Operations in Less Example: Impossible conversion: px to cm or rad to %. // numbers are converted into the same units @conversion-1: 5cm + 10mm; // result is 6cm @conversion-2: 2 - 3cm - 5mm; // result is -1.5cm // conversion is impossible @incompatible-units: 2 + 5px - 3cm; // result is 4px // example with variables @base: 5%; @filler: @base * 2; // result is 10% @other: @base + @filler; // result is 15% Example: Multiplication and division do not convert numbers. @base: 2cm * 3mm; // result is 6cm Example: Arithmetic on colors @color: #224488 / 2; //results in #112244 background-color : #112244 + #111; // result is #223355 Example: Colors functions saturate(hsl(90, 80%, 50%), 20%) =>#80ff00 // hsl(90, 100%, 50%) lighten(hsl(90, 80%, 50%), 20%) => #b3f075 // hsl(90, 80%, 70%) darken(hsl(90, 80%, 50%), 20%) => #4d8a0f // hsl(90, 80%, 30%) fade(hsl(90, 90%, 50%), 10%) => rgba(128, 242, 13, 0.1) //hsla(90, 90%, 50%, 0.1)
  • 14. Operations (calc() exception) in Less calc() function does not evaluate math expressions for CSS compatibility, but it evaluates variables and math in nested functions. @var: 50vh/2; width: calc(50% + (@var - 20px)); // output is calc(50% + (25vh - 20px))
  • 15. Functions in Less Less provides a variety of functions which transform colors, manipulate strings and do maths @base: #f04615; @width: 0.5; .class { width: percentage(@width); // returns `50%` color: saturate(@base, 5%); background-color : spin(lighten(@base, 25%), 8); } Using them is pretty straightforward. This example uses percentage to convert 0.5 to 50%, increases the saturation of a base color by 5% and then sets the background color to one that is lightened by 25% and spun by 8 degrees.
  • 16. Namespaces and Accessors in Less Sometimes, you may want to group your mixins, for organizational purposes, or just to offer some encapsulation. You can do this pretty intuitively in Less. Example: if we want to bundle some mixins and variables under #bundle, for later reuse or distributing. #bundle() { .button { display: block; border: 1px solid black; background-color : grey; &:hover { background-color : white; } } .tab { ... } .citation { ... } } Now if we want to mixin the .button class in our #header a, we can do #header a { color: orange; #bundle.button(); // can also be written as #bundle > .button } Note: append () to your namespace (e.g. #bundle()) if you don't want it to appear in your CSS output i.e. #bundle .tab.
  • 17. Escaping in Less Escaping allows you to use any arbitrary string as property or variable value. Anything inside ~"anything" or ~'anything' is used as is with no changes except interpolation. @min768: ~"(min-width: 768px)" ; .element { @media @min768 { font-size: 1.2rem; } } @media (min-width: 768px) { .element { font-size: 1.2rem; } } In Less 3.5, you can simply write. In 3.5+, many cases previously requiring "quote-escaping" are not needed. @min768: (min-width: 768px); .element { @media @min768 { font-size: 1.2rem; } }
  • 18. Maps in Less We can also use mixins and rulesets as maps of values #colors() { primary: blue; secondary: green; } .button { color: #colors[primary]; border: 1px solid #colors[secondary]; } .button { color: blue; border: 1px solid green; }
  • 19. Scope in Less Scope in Less is very similar to that of CSS. Variables and mixins are first looked for locally, and if they aren't found, it's inherited from the "parent" scope. @var: red; #page { @var: white; #header { color: @var; // white } } @var: red; #page { #header { color: @var; // white } @var: white; }
  • 20. Installing, configuring and usages of Less - Command Line Usag - https://lesscss.org/usage/#command-line-usage - Browser Usage - https://lesscss.org/usage/#using-less-in-the-browser Supports: - Less.js supports all modern browsers (recent versions of Chrome, Firefox, Safari, IE11+, and Edge). - It is possible to use Less on the client side in production, please be aware that there are performance implications for doing so (although the latest releases of Less are quite a bit faster). - Sometimes cosmetic issues can occur if a JavaScript error occurs. This is a trade off of flexibility vs. speed. - For the fastest performance possible for a static web site, - We recommend compiling Less on the server side.
  • 21. Installing, configuring and usages of Less 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> Need to keep in mind: - Make sure you include your stylesheets before the script. - When you link more than one .less stylesheet each of them is compiled independently. So any variables, mixins or namespaces you define in a stylesheet are not accessible in any other. - Due to the same origin policy of browsers, loading external resources requires enabling CORS
  • 22. Installing, configuring and usages of Less You can set options either programmatically, by setting them on a less object before the script tag - this then affects all initial link tags and programmatic usage of less. <script> less = { env: "development", async: false, fileAsync: false, poll: 1000, functions: {}, dumpLineNumbers : "comments", relativeUrls: false, rootpath: ":/a.com/" }; </script> <script src="less.js"></script> The other way is to specify the options on the script tag, e.g. <script> less = { env: "development" }; </script> <script src="less.js" data-env="development"></script> Or for brevity they can be set as attributes on the script and link tags <script src="less.js" data-poll ="1000" data-relative-urls ="false"></script> <link data-dump-line-numbers ="all" data-global-vars ='{ "myvar": "#ddffee", "mystr": ""quoted"" }' rel="stylesheet/less" type="text/css" href="less/styles.less" >
  • 23. Pros and Cons of Less ??? Cons: - The learning curve - Could inherit mistakes of framework developer - Could lead to a lack of understanding the underlying css - Bloated code - Might restrict you as you conform to the framework - Lack of semantic code Pros: - Increased productivity - Standardized codebase - Makes it easier to work with a team - Provides a more organized approach to css - Publicly released frameworks are improved by the community - Fewer mistakes - Cross browser reliability - Can be a learning tool
  • 24. Would you like to learn more about Less? - Overview: http://lesscss.org/ - Usages: https://lesscss.org/usage/#using-less-in-the-browser - Functions: https://lesscss.org/functions/ - Features: https://lesscss.org/features/ - Tools: https://lesscss.org/tools/ - Editors and Editor Plugins: https://lesscss.org/tools/#editors-and-plugins - Contributing?: https://lesscss.org/usage/#developing-less - More: https://www.tutorialspoint.com/less/index.htm
  • 25. Question? Sanjoy K. Paul Lead Application Developer | Software Architect | DevOps | Trainer www.SanjoyPaul.com | skpaul@DevsStation.com | +880-1511-927992