SlideShare a Scribd company logo
LESS is More
Getting More out of CSS with Pre-Processors
Sara Laupp
@slauppy
● First website in 2002
● Full Stack Developer - 5 years
● Custom web applications at
consulting firm
● Software Engineer at Enova
HTML
CSS
jQuery
AngularJS
PHP
MySQL
Redis
Ruby
Rails
Postgresql
What is a CSS Pre-Processor?
Extension of CSS
Compiles into CSS syntax
LESS or SASS?
● Both have the same basic features
● Syntax preference
● Dependency preference
Use SASS when...
● Ruby dependency is fine
● You prefer the Ruby syntax
○ SASS is NOT backwards compatible with CSS
○ SCSS (Sassy CSS) is backwards compatible with CSS
● Your project is using Ruby/Rails
● Frameworks with SASS support:
○ Rails
○ Laravel
Use LESS when...
● NodeJS dependency is fine
● You prefer the CSS code style
○ LESS is backwards compatible with CSS
● Frameworks with built-in LESS support
○ Laravel
LESS is More...
● Controllable
● Maintainable
● Robust
● Programmatic
Why is this better than CSS?
button, a.button {
display: inline-block;
padding: 6px 10px;
background-color: #551155;
font-family: Georgia, serif;
font-style: italic;
color: #E0D8E0;
font-size: 1.1em;
line-height: 1.5em;
border-top: 2px solid #E0D8E0;
border-right: 2px solid #000000;
border-bottom: 2px solid #000000;
border-left: 2px solid #E0D8E0;
}
button:hover, a.button:hover {
background-color: #FFFFFF;
color: #330033;
border-top: 2px solid #443D44;
border-right: 2px solid #E0D8E0;
border-bottom: 2px solid #E0D8E0;
border-left: 2px solid #443D44;
cursor: pointer;
}
Button Example: CSS
@dark-purple: #551155;
@light-gray: #E0D8E0;
@dark-gray: #443D44;
@almost-black: #330033;
.bordered(@left-color, @right-color) {
border-top: 2px solid @left-color;
border-right: 2px solid @right-color;
border-bottom: 2px solid @right-color;
border-left: 2px solid @left-color;
}
button, a.button {
display: inline-block;
padding: 6px 10px;
background-color: @dark-purple;
font-family: Georgia, serif;
font-style: italic;
color: @light-gray;
font-size: 1.1em;
line-height: 1.5em;
.bordered(@light-gray, @almost-black);
&:hover {
background-color: white;
color: @almost-black;
.bordered(@dark-gray, @light-gray);
cursor: pointer;
}
}
Button Example: LESS
DRY,
Maintainable Code!
What’s the big deal?
LESS Setup
Install npm
Manually compile into css
Link your CSS in HTML as usual:
$ npm install -g less
$ lessc styles.less styles.css
<link rel="stylesheet" type="text/css" href="styles.css" />
Autocompiling on the Client Side
<link rel="stylesheet/less" type="text/css" href="styles.less" />
<script src="less.js" type="text/javascript"></script>
Compiles on every page load in the browser.
Not meant for use in production!
<link rel="stylesheet/less" type="text/css" href="styles.less" />
<script src="less.js" type="text/javascript"></script>
Autocompiling During Development
Watch your LESS files with
● Grunt - https://github.com/gruntjs/grunt-contrib-less
● autoless - https://github.com/jgonera/autoless
Link to the compiled CSS as usual
<link rel="stylesheet" type="text/css" href="styles.css" />
CSS Pre-Processor Features
● Variables
● Mixins
● Nested rules
● Operators
● Basic inheritance
● Function library
Variables
@nice-blue: #5B83AD;
@light-yellow: #000000;
#header {
background-color: @nice-blue;
color: @light-yellow;
}
button.default {
background-color: @light-yellow;
color: @nice-blue;
}
#header {
background-color: #5B83AD;
color: #000000;
}
button.default {
background-color: #000000;
color: #5B83AD;
}
Mixins
.dotted-border {
border-top: dotted 2px red;
border-bottom: dotted 1px red;
}
#breadcrumbs a {
color: #111;
.dotted-border;
}
.dotted a {
color: red;
.dotted-border;
}
#breadcrumbs a {
color: #111;
border-top: dotted 2px red;
border-bottom: dotted 1px red;
}
.dotted a {
color: red;
border-top: dotted 2px red;
border-bottom: dotted 1px red;
}
Nested Rules
a {
text-decoration: none;
color: #880099;
&:visited {
color: #E0D8E0;
}
&:hover,
&:visited:hover,
&:active {
color: #330033;
}
}
a {
text-decoration: none;
color: #880099;
}
a:visited {
color: #E0D8E0;
}
a:hover,
a:visited:hover,
a:active {
color: #330033;
}
Operators
@base-width: 5%;
@base-color: #224488
@lighter-color: #112244 + #111;
#sidebar {
max-width: @base-width;
color: @base-color;
background-color: @base-color / 2;
}
#filler {
max-width: @base-width * 2;
color: @lighter-color;
}
#sidebar {
max-width: 5%;
color: #224488;
background-color: #112244;
}
#filler {
max-width: 10%;
color: #223355;
}
Basic Inheritance (extend)
.button-default {
font-size: 1.2em;
font-weight: bold;
color: black;
background-color: white;
}
.button-submit {
&:extend(.button-default);
color: white;
background-color: black;
}
.button-default {
font-size: 1.2em;
font-weight: bold;
color: black;
background-color: white;
}
.button-submit,
.button-default {
color: white;
background-color: black;
}
Function Library
@purple: mix(#ff0000, #0000ff, 50%);
@color-base : #800080;
@color-complement : spin(@color-base, 180);
Supported function types:
● String manipulation
● Math (abs, sqrt, etc…)
● Color manipulation
● http://lesscss.org/functions/
References
● LESS: http://lesscss.org/
● SASS: http://sass-lang.com/
● Laravel LESS & SASS Documentation: https://laravel.com/docs/5.1/elixir#working-
with-stylesheets
● Rails SASS Documentation: https://github.com/rails/sass-rails
● LESS Color Manipulation Tutorial: http://webdesign.tutsplus.
com/tutorials/creating-color-schemes-with-less-color-functions--cms-23668
?

More Related Content

What's hot

Developing JavaScript Widgets
Developing JavaScript WidgetsDeveloping JavaScript Widgets
Developing JavaScript Widgets
Bob German
 
CSS Eye for the Programmer Guy
CSS Eye for the Programmer GuyCSS Eye for the Programmer Guy
CSS Eye for the Programmer Guy
Dennis Slade Jr.
 
Keystone.js 101
Keystone.js 101Keystone.js 101
Keystone.js 101
Alexander Roche
 
Learning Single page Application chapter 1
Learning Single page Application chapter 1Learning Single page Application chapter 1
Learning Single page Application chapter 1
Puguh Rismadi
 
Javascript & Jquery
Javascript & JqueryJavascript & Jquery
Javascript & Jquery
Gurpreet singh
 
Front-End Frameworks: a quick overview
Front-End Frameworks: a quick overviewFront-End Frameworks: a quick overview
Front-End Frameworks: a quick overview
Diacode
 
Introduction to JavaScript Full Stack
Introduction to JavaScript Full StackIntroduction to JavaScript Full Stack
Introduction to JavaScript Full Stack
Mindfire Solutions
 
WordPress & Backbone.js
WordPress & Backbone.jsWordPress & Backbone.js
WordPress & Backbone.js
Andrew Duthie
 
Word press development for non developers
Word press development for non developers Word press development for non developers
Word press development for non developers
Jessica C. Gardner
 
Making Single Page Applications (SPA) faster
Making Single Page Applications (SPA) faster Making Single Page Applications (SPA) faster
Making Single Page Applications (SPA) faster
Boris Livshutz
 
Going Multi-Tenant with dotCMS
Going Multi-Tenant with dotCMSGoing Multi-Tenant with dotCMS
Going Multi-Tenant with dotCMS
dotCMS
 
Developing JavaScript Widgets
Developing JavaScript WidgetsDeveloping JavaScript Widgets
Developing JavaScript Widgets
Bob German
 
Angular js introduction
Angular js introductionAngular js introduction
Angular js introduction
Praveen Gubbala
 
A Gentle Introduction to Blazor
A Gentle Introduction to BlazorA Gentle Introduction to Blazor
A Gentle Introduction to Blazor
Jose Javier Columbie
 
Why You Need a Front End Developer
Why You Need a Front End DeveloperWhy You Need a Front End Developer
Why You Need a Front End Developer
Mike Wilcox
 
Rise of the responsive single page application
Rise of the responsive single page applicationRise of the responsive single page application
Rise of the responsive single page applicationOren Shatken
 
Less presentation
Less presentationLess presentation
Less presentation
Todd Shelton
 
Single page applications
Single page applicationsSingle page applications
Single page applications
Prafful Garg
 
Iseltech17 - Single Page Applications
Iseltech17 - Single Page ApplicationsIseltech17 - Single Page Applications
Iseltech17 - Single Page Applications
Monica Rodrigues
 
Angular.js in XPages
Angular.js in XPagesAngular.js in XPages
Angular.js in XPages
Mark Roden
 

What's hot (20)

Developing JavaScript Widgets
Developing JavaScript WidgetsDeveloping JavaScript Widgets
Developing JavaScript Widgets
 
CSS Eye for the Programmer Guy
CSS Eye for the Programmer GuyCSS Eye for the Programmer Guy
CSS Eye for the Programmer Guy
 
Keystone.js 101
Keystone.js 101Keystone.js 101
Keystone.js 101
 
Learning Single page Application chapter 1
Learning Single page Application chapter 1Learning Single page Application chapter 1
Learning Single page Application chapter 1
 
Javascript & Jquery
Javascript & JqueryJavascript & Jquery
Javascript & Jquery
 
Front-End Frameworks: a quick overview
Front-End Frameworks: a quick overviewFront-End Frameworks: a quick overview
Front-End Frameworks: a quick overview
 
Introduction to JavaScript Full Stack
Introduction to JavaScript Full StackIntroduction to JavaScript Full Stack
Introduction to JavaScript Full Stack
 
WordPress & Backbone.js
WordPress & Backbone.jsWordPress & Backbone.js
WordPress & Backbone.js
 
Word press development for non developers
Word press development for non developers Word press development for non developers
Word press development for non developers
 
Making Single Page Applications (SPA) faster
Making Single Page Applications (SPA) faster Making Single Page Applications (SPA) faster
Making Single Page Applications (SPA) faster
 
Going Multi-Tenant with dotCMS
Going Multi-Tenant with dotCMSGoing Multi-Tenant with dotCMS
Going Multi-Tenant with dotCMS
 
Developing JavaScript Widgets
Developing JavaScript WidgetsDeveloping JavaScript Widgets
Developing JavaScript Widgets
 
Angular js introduction
Angular js introductionAngular js introduction
Angular js introduction
 
A Gentle Introduction to Blazor
A Gentle Introduction to BlazorA Gentle Introduction to Blazor
A Gentle Introduction to Blazor
 
Why You Need a Front End Developer
Why You Need a Front End DeveloperWhy You Need a Front End Developer
Why You Need a Front End Developer
 
Rise of the responsive single page application
Rise of the responsive single page applicationRise of the responsive single page application
Rise of the responsive single page application
 
Less presentation
Less presentationLess presentation
Less presentation
 
Single page applications
Single page applicationsSingle page applications
Single page applications
 
Iseltech17 - Single Page Applications
Iseltech17 - Single Page ApplicationsIseltech17 - Single Page Applications
Iseltech17 - Single Page Applications
 
Angular.js in XPages
Angular.js in XPagesAngular.js in XPages
Angular.js in XPages
 

Similar to LESS is More (ChiHTML5 Meetup June 2016)

Structuring your CSS for maintainability: rules and guile lines to write CSS
Structuring your CSS for maintainability: rules and guile lines to write CSSStructuring your CSS for maintainability: rules and guile lines to write CSS
Structuring your CSS for maintainability: rules and guile lines to write CSS
Sanjoy Kr. Paul
 
Angular 2 vs React
Angular 2 vs ReactAngular 2 vs React
Angular 2 vs React
Iran Reyes Fleitas
 
Team styles
Team stylesTeam styles
Team styles
nathanscott
 
04 CSS #burningkeyboards
04 CSS #burningkeyboards04 CSS #burningkeyboards
04 CSS #burningkeyboards
Denis Ristic
 
Kalastatic: Design+Content-first approaches to static prototyping
Kalastatic: Design+Content-first approaches to static prototypingKalastatic: Design+Content-first approaches to static prototyping
Kalastatic: Design+Content-first approaches to static prototyping
Andrew Mallis
 
Intro to html5 Boilerplate
Intro to html5 BoilerplateIntro to html5 Boilerplate
Intro to html5 Boilerplate
Michael Enslow
 
10 Tips to make your Website lightning-fast - SMX Stockholm 2012
10 Tips to make your Website lightning-fast - SMX Stockholm 201210 Tips to make your Website lightning-fast - SMX Stockholm 2012
10 Tips to make your Website lightning-fast - SMX Stockholm 2012
Bastian Grimm
 
Not Just a Pretty Face: How to design and build a cross-CMS CSS framework
Not Just a Pretty Face: How to design and build a cross-CMS CSS frameworkNot Just a Pretty Face: How to design and build a cross-CMS CSS framework
Not Just a Pretty Face: How to design and build a cross-CMS CSS framework
crystalenka
 
Web Development Today
Web Development TodayWeb Development Today
Web Development Today
bretticus
 
Using a CSS Framework
Using a CSS FrameworkUsing a CSS Framework
Using a CSS Framework
Gareth Saunders
 
Front end frameworks
Front end frameworksFront end frameworks
Front end frameworks
Madushan Sandaruwan
 
Introducing grunt, npm and sass
Introducing grunt, npm and sassIntroducing grunt, npm and sass
Introducing grunt, npm and sass
priyanka1452
 
Architektura html, css i javascript - Jan Kraus
Architektura html, css i javascript - Jan KrausArchitektura html, css i javascript - Jan Kraus
Architektura html, css i javascript - Jan Kraus
Women in Technology Poland
 
LESS(CSS Pre Processor) introduction
LESS(CSS Pre Processor) introductionLESS(CSS Pre Processor) introduction
LESS(CSS Pre Processor) introduction
rushi7567
 
Less(CSS Pre Processor) Introduction
Less(CSS Pre Processor) IntroductionLess(CSS Pre Processor) Introduction
Less(CSS Pre Processor) Introduction
rushi7567
 
Best Practices for Building WordPress Applications
Best Practices for Building WordPress ApplicationsBest Practices for Building WordPress Applications
Best Practices for Building WordPress Applications
Taylor Lovett
 
Using Sass in Your WordPress Projects
Using Sass in Your WordPress ProjectsUsing Sass in Your WordPress Projects
Using Sass in Your WordPress Projects
Jeremy Green
 
LESS CSS
LESS CSSLESS CSS
Test-proof CSS
Test-proof CSSTest-proof CSS
Test-proof CSS
Vittorio Vittori
 
UNIT 3.ppt
UNIT 3.pptUNIT 3.ppt
UNIT 3.ppt
kavi806657
 

Similar to LESS is More (ChiHTML5 Meetup June 2016) (20)

Structuring your CSS for maintainability: rules and guile lines to write CSS
Structuring your CSS for maintainability: rules and guile lines to write CSSStructuring your CSS for maintainability: rules and guile lines to write CSS
Structuring your CSS for maintainability: rules and guile lines to write CSS
 
Angular 2 vs React
Angular 2 vs ReactAngular 2 vs React
Angular 2 vs React
 
Team styles
Team stylesTeam styles
Team styles
 
04 CSS #burningkeyboards
04 CSS #burningkeyboards04 CSS #burningkeyboards
04 CSS #burningkeyboards
 
Kalastatic: Design+Content-first approaches to static prototyping
Kalastatic: Design+Content-first approaches to static prototypingKalastatic: Design+Content-first approaches to static prototyping
Kalastatic: Design+Content-first approaches to static prototyping
 
Intro to html5 Boilerplate
Intro to html5 BoilerplateIntro to html5 Boilerplate
Intro to html5 Boilerplate
 
10 Tips to make your Website lightning-fast - SMX Stockholm 2012
10 Tips to make your Website lightning-fast - SMX Stockholm 201210 Tips to make your Website lightning-fast - SMX Stockholm 2012
10 Tips to make your Website lightning-fast - SMX Stockholm 2012
 
Not Just a Pretty Face: How to design and build a cross-CMS CSS framework
Not Just a Pretty Face: How to design and build a cross-CMS CSS frameworkNot Just a Pretty Face: How to design and build a cross-CMS CSS framework
Not Just a Pretty Face: How to design and build a cross-CMS CSS framework
 
Web Development Today
Web Development TodayWeb Development Today
Web Development Today
 
Using a CSS Framework
Using a CSS FrameworkUsing a CSS Framework
Using a CSS Framework
 
Front end frameworks
Front end frameworksFront end frameworks
Front end frameworks
 
Introducing grunt, npm and sass
Introducing grunt, npm and sassIntroducing grunt, npm and sass
Introducing grunt, npm and sass
 
Architektura html, css i javascript - Jan Kraus
Architektura html, css i javascript - Jan KrausArchitektura html, css i javascript - Jan Kraus
Architektura html, css i javascript - Jan Kraus
 
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
 
Best Practices for Building WordPress Applications
Best Practices for Building WordPress ApplicationsBest Practices for Building WordPress Applications
Best Practices for Building WordPress Applications
 
Using Sass in Your WordPress Projects
Using Sass in Your WordPress ProjectsUsing Sass in Your WordPress Projects
Using Sass in Your WordPress Projects
 
LESS CSS
LESS CSSLESS CSS
LESS CSS
 
Test-proof CSS
Test-proof CSSTest-proof CSS
Test-proof CSS
 
UNIT 3.ppt
UNIT 3.pptUNIT 3.ppt
UNIT 3.ppt
 

Recently uploaded

Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 

Recently uploaded (20)

Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 

LESS is More (ChiHTML5 Meetup June 2016)

  • 1. LESS is More Getting More out of CSS with Pre-Processors
  • 2. Sara Laupp @slauppy ● First website in 2002 ● Full Stack Developer - 5 years ● Custom web applications at consulting firm ● Software Engineer at Enova HTML CSS jQuery AngularJS PHP MySQL Redis Ruby Rails Postgresql
  • 3. What is a CSS Pre-Processor? Extension of CSS Compiles into CSS syntax
  • 4. LESS or SASS? ● Both have the same basic features ● Syntax preference ● Dependency preference
  • 5. Use SASS when... ● Ruby dependency is fine ● You prefer the Ruby syntax ○ SASS is NOT backwards compatible with CSS ○ SCSS (Sassy CSS) is backwards compatible with CSS ● Your project is using Ruby/Rails ● Frameworks with SASS support: ○ Rails ○ Laravel
  • 6. Use LESS when... ● NodeJS dependency is fine ● You prefer the CSS code style ○ LESS is backwards compatible with CSS ● Frameworks with built-in LESS support ○ Laravel
  • 7. LESS is More... ● Controllable ● Maintainable ● Robust ● Programmatic Why is this better than CSS?
  • 8. button, a.button { display: inline-block; padding: 6px 10px; background-color: #551155; font-family: Georgia, serif; font-style: italic; color: #E0D8E0; font-size: 1.1em; line-height: 1.5em; border-top: 2px solid #E0D8E0; border-right: 2px solid #000000; border-bottom: 2px solid #000000; border-left: 2px solid #E0D8E0; } button:hover, a.button:hover { background-color: #FFFFFF; color: #330033; border-top: 2px solid #443D44; border-right: 2px solid #E0D8E0; border-bottom: 2px solid #E0D8E0; border-left: 2px solid #443D44; cursor: pointer; } Button Example: CSS
  • 9. @dark-purple: #551155; @light-gray: #E0D8E0; @dark-gray: #443D44; @almost-black: #330033; .bordered(@left-color, @right-color) { border-top: 2px solid @left-color; border-right: 2px solid @right-color; border-bottom: 2px solid @right-color; border-left: 2px solid @left-color; } button, a.button { display: inline-block; padding: 6px 10px; background-color: @dark-purple; font-family: Georgia, serif; font-style: italic; color: @light-gray; font-size: 1.1em; line-height: 1.5em; .bordered(@light-gray, @almost-black); &:hover { background-color: white; color: @almost-black; .bordered(@dark-gray, @light-gray); cursor: pointer; } } Button Example: LESS
  • 12. LESS Setup Install npm Manually compile into css Link your CSS in HTML as usual: $ npm install -g less $ lessc styles.less styles.css <link rel="stylesheet" type="text/css" href="styles.css" />
  • 13. Autocompiling on the Client Side <link rel="stylesheet/less" type="text/css" href="styles.less" /> <script src="less.js" type="text/javascript"></script> Compiles on every page load in the browser. Not meant for use in production! <link rel="stylesheet/less" type="text/css" href="styles.less" /> <script src="less.js" type="text/javascript"></script>
  • 14. Autocompiling During Development Watch your LESS files with ● Grunt - https://github.com/gruntjs/grunt-contrib-less ● autoless - https://github.com/jgonera/autoless Link to the compiled CSS as usual <link rel="stylesheet" type="text/css" href="styles.css" />
  • 15. CSS Pre-Processor Features ● Variables ● Mixins ● Nested rules ● Operators ● Basic inheritance ● Function library
  • 16. Variables @nice-blue: #5B83AD; @light-yellow: #000000; #header { background-color: @nice-blue; color: @light-yellow; } button.default { background-color: @light-yellow; color: @nice-blue; } #header { background-color: #5B83AD; color: #000000; } button.default { background-color: #000000; color: #5B83AD; }
  • 17. Mixins .dotted-border { border-top: dotted 2px red; border-bottom: dotted 1px red; } #breadcrumbs a { color: #111; .dotted-border; } .dotted a { color: red; .dotted-border; } #breadcrumbs a { color: #111; border-top: dotted 2px red; border-bottom: dotted 1px red; } .dotted a { color: red; border-top: dotted 2px red; border-bottom: dotted 1px red; }
  • 18. Nested Rules a { text-decoration: none; color: #880099; &:visited { color: #E0D8E0; } &:hover, &:visited:hover, &:active { color: #330033; } } a { text-decoration: none; color: #880099; } a:visited { color: #E0D8E0; } a:hover, a:visited:hover, a:active { color: #330033; }
  • 19. Operators @base-width: 5%; @base-color: #224488 @lighter-color: #112244 + #111; #sidebar { max-width: @base-width; color: @base-color; background-color: @base-color / 2; } #filler { max-width: @base-width * 2; color: @lighter-color; } #sidebar { max-width: 5%; color: #224488; background-color: #112244; } #filler { max-width: 10%; color: #223355; }
  • 20. Basic Inheritance (extend) .button-default { font-size: 1.2em; font-weight: bold; color: black; background-color: white; } .button-submit { &:extend(.button-default); color: white; background-color: black; } .button-default { font-size: 1.2em; font-weight: bold; color: black; background-color: white; } .button-submit, .button-default { color: white; background-color: black; }
  • 21. Function Library @purple: mix(#ff0000, #0000ff, 50%); @color-base : #800080; @color-complement : spin(@color-base, 180); Supported function types: ● String manipulation ● Math (abs, sqrt, etc…) ● Color manipulation ● http://lesscss.org/functions/
  • 22. References ● LESS: http://lesscss.org/ ● SASS: http://sass-lang.com/ ● Laravel LESS & SASS Documentation: https://laravel.com/docs/5.1/elixir#working- with-stylesheets ● Rails SASS Documentation: https://github.com/rails/sass-rails ● LESS Color Manipulation Tutorial: http://webdesign.tutsplus. com/tutorials/creating-color-schemes-with-less-color-functions--cms-23668
  • 23. ?