SlideShare a Scribd company logo
YOOXlabs ~ 22.09.2015
andreaverlicchi.eu ~ @verlok ~ #YOOXlabsTechEvent
Agile CSS Development
with Compass / SASS
• Strong addiction to
front-end development
• Front-end Architect
• Occasional speaker
andreaverlicchi.eu ~ @verlok ~ #YOOXlabsTechEvent
YOOXlabs Tech Event
Front-End Development
October 2015
Agile CSS development with Compass and Sass
Language
Repetitive
Length
Mess?
Maintenance
Sass is the most mature, stable, and powerful
professional grade CSS extension language in the world.
How it works: locally
FILE .SCSS
FILE .CSS
WATCHGRUNT
How it works: CI
FILE .SCSS
COMPILE
FILE .CSS
button {
background: #ABCDEF;
}
a {
color: #ABCDEF;
}
header {
border-bottom: 5px;
border-color: #ABCDEF;
}
$mainColor: #ABCDEF;
button {
background: $mainColor;
}
a {
color: $mainColor;
}
header {
border-bottom: 5px;
border-color: $mainColor;
}
Variables
Nesting
article h1 {
margin-right: 1em;
}
article a {
color: white;
background: red;
display: block;
}
article a:hover {
color: red;
background: white;
}
article {
h1 {
margin-right: 1em;
}
a {
color: white;
background: red;
display: block;
&:hover {
color: red;
background: white;
}
}
}
Math
aside {
width: 23.95833%;
}
$width: 960px;
$asideWidth: 230px;
aside {
width: $asideWidth / $width * 100%;
}
Partials
@import “_variables”;
@import "_reset";
@import "_fonts";
@import "_headerFooter";
@import "_forms";
@import "_base";
@import "_helpers";
@import “_whatever”;
…
main.scss main.css
// _reset.scss
html, body, div, span, h1,
h2, h3, h4, h5, h6 … {
margin: 0; padding: 0; …
} // …
// _fonts.scss
@font-face {
font-family: myFont; //…
} // …
// …
// _whatever.scss
Helpers
button:hover {
background-color:

#A6CDF4;
}
button.disabled {
background-color:

#C4CDD6;
}
$buttonColor: #ABCDEF;
button:hover {
background-color: 

adjust-saturation($buttonColor, 10%);
}
button.disabled {
background-color: 

adjust-saturation($buttonColor, -10%);
}
Extend
.message {
font-weight: bold;
padding: 1em;
border-width: 2px;
}
.error {
@extend .message;
color: red;
border-color: red;
}
.alert {
@extend .message;
color: orange;
border-color: orange;
}
.message, .error, .alert {
font-weight: bold;
padding: 1em;
border-width: 2px;
}
.error {
color: red;
border-color: red;
}
.alert {
color: orange;
border-color: orange;
}
Extend
%message {
font-weight: bold;
padding: 1em;
border-width: 2px;
}
.error {
@extend %message;
color: red;
border-color: red;
}
.alert {
@extend %message;
color: orange;
border-color: orange;
}
.error, .alert {
font-weight: bold;
padding: 1em;
border-width: 2px;
}
.error {
color: red;
border-color: red;
}
.alert {
color: orange;
border-color: orange;
}
Mixins
@mixin message {
font-weight: bold;
padding: 1em;
border-width: 2px;
}
.error {
@include message;
color: red;
border-color: red;
}
.alert {
@include message;
color: orange;
border-color: orange;
}
.error {
font-weight: bold;
padding: 1em;
border-width: 2px;
color: red;
border-color: red;
}
.alert {
font-weight: bold;
padding: 1em;
border-width: 2px;
color: orange;
border-color: orange;
}
Extend vs Mixins
• CSS length
• Usage with media queries
• Parameters
EXTEND WINS
MIXIN WINS
MIXIN WINS
Mixins
@mixin opacity($opacity) {
opacity: $opacity;
filter: alpha(opacity=$opacity*100);
}
.faded-text {
@include opacity(0.8);
}
.faded-text {
opacity: 0.8;
filter: alpha(opacity=80);
}
Output style
• nested .widget-social {
text-align: right; }
.widget-social a,
.widget-social a:visited {
padding: 0 3px;
color: #222222; }
.widget-social a:hover {
color: #B00909; }
Output style
• nested
• expanded
.widget-social {
text-align: right;
}
.widget-social a,
.widget-social a:visited {
padding: 0 3px;
color: #222222;
}
.widget-social a:hover {
color: #B00909;
}
Output style
• nested
• expanded
• compact
.widget-social { text-align: right; }
.widget-social a, .widget-social a:visited { padding: 0 3px; … }
.widget-social a:hover { color: #B00909; }
Output style
• nested
• expanded
• compact
• compressed
.widget-social{text-align:right}.widget-social a,.widget-social
a:visited{padding:0 3px;color:#222222}.widget-social a:hover{co
lor:#B00909}
Debug
• source maps
• line comments
SASS
• Variables
• Nesting
• Math
• Partials
• Extend
• Mixins
Compass is an open-source CSS Authoring Framework.
Compass uses SASS.
Browser thresholds
Thresholds configuration
// Dichiarare prima di @import-are compass
$graceful-usage-threshold: 5; // def: 0.1
$critical-usage-threshold: 1; // def: 0.01
@import "compass/css3";
// Tutto il resto a seguire...
251 included mixing
Background & Gradients
.myBox {
@include background(linear-gradient(to bottom, #F00, #0F0));
}
.myBox {
// ...
background: -moz-linear-gradient(top, #ff0000, #00ff00);
background: -webkit-linear-gradient(top, #ff0000, #00ff00);
background: linear-gradient(to bottom, #ff0000, #00ff00);
}
Keyframes
@include keyframes(spin) {
from { transform: rotate(0); }
to { transform: rotate(360deg); }
}
@-moz-keyframes spin { ... }
@-webkit-keyframes spin { ... }
@keyframes spin {
from { transform: rotate(0); }
to { transform: rotate(360deg); }
}
Animation
.myBox {
@include animation(spin 1s);
}
.myBox {
-moz-animation: spin 1s;
-webkit-animation: spin 1s;
animation: spin 1s;
}
Flexbox
.parent {
@include display-flex;
@include flex-wrap(wrap);
}
.child {
@include flex-grow(1);
}
.parent {
display: -webkit-flex;
display: flex;
-webkit-flex-wrap: wrap;
flex-wrap: wrap;
}
.child {
-webkit-flex-grow: 1;
flex-grow: 1;
}
http://compass-style.org/index/mixins
Sprites
Sprites - All
@import “compass/utilities/sprites";
@import "flags/*.png";
@include all-flags-sprites;
.flags-it,
.flags-de,
.flags-fr {
background: url('/images/flags-s34fe0604ab.png') no-repeat;
}
.flags-it { background-position: 0 0; }
.flags-de { background-position: 0 -32px; }
.flags-fr { background-position: 0 -64px; }
// flags
// it.png
// de.png
// fr.png
Sprite - Single
@import "compass/utilities/sprites";
@import "flags/*.png";
// it.png
// de.png
.myBox {
@include flags-sprite(it);
}
.anotherBox {
@include flags-sprite(de);
}
.myBox,
.anotherBox {
background: url('../img/flags-
s69e070e3f8.png') no-repeat;
}
.myBox {
background-position: 0 0;
}
.anotherBox {
background-position: 0 -32px;
}
Sprite - Advanced
• Box size generation
• Offset inside the box
• Sprite images spacing
• Display density management
• Here’s how:

andreaverlicchi.eu/yooxlabs-2015-09/
Installation
• Download Ruby

rubyinstaller.org
• Install Compass
• Download Ruby

ruby-lang.com
• Install Compass
gem install compasssudo
Configuration
• Activate the project folder
• Create the configuration file
cd path/to/project
compass config --css-dir css
Primi file SASS
• Convert CSS to SCSS
sass-convert css/main.css --to scss
• Create initial folders and files
compass install compass
sass-convert css --to scss --recursive
Usage
• Compile
compass compile
• Start the watcher
compass watch
Compass
• Sprite
• Browser thresholds
• Included mixins
• Project organization
• Development speed
• Maintain with ease
Agile CSS development with Compass and Sass
Q&A
@verlok ~ #YOOXlabsTechEvent
SASS vs LESS
@verlok ~ #YOOXlabsTechEvent
https://css-tricks.com/sass-vs-less/
http://www.zingdesign.com/less-vs-sass-its-time-to-
switch-to-sass/

More Related Content

PPT
An Introduction to CSS Preprocessors (SASS & LESS)
PPT
CSS Preprocessors: LESS is more or look SASS-y trying
PPTX
Write LESS. DO more.
PPTX
Syntactically awesome stylesheets (Sass)
PPTX
Less css
PDF
Sass - Getting Started with Sass!
PPTX
From PSD to WordPress Theme: Bringing designs to life
PDF
An Introduction to CSS Preprocessors (SASS & LESS)
CSS Preprocessors: LESS is more or look SASS-y trying
Write LESS. DO more.
Syntactically awesome stylesheets (Sass)
Less css
Sass - Getting Started with Sass!
From PSD to WordPress Theme: Bringing designs to life

What's hot (20)

ODP
Sass presentation
PDF
The Future of CSS
KEY
Intro to SASS CSS
PPTX
Doing More With Less
ODP
HTML5, CSS, JavaScript Style guide and coding conventions
PPT
Ppt ch05
PDF
CSS 開發加速指南-Sass & Compass
PDF
LESS, the CSS Preprocessor
PDF
CSS3 3D Workshop
PDF
Intro to Sass for WordPress Developers
PPTX
BDUG Responsive Web Theming - 7/23/12
PDF
How to use CSS3 in WordPress
PDF
How to use CSS3 in WordPress - Sacramento
PDF
Sass and compass workshop
PDF
Using LESS, the CSS Preprocessor: J and Beyond 2013
PDF
Quality Development with CSS3
PDF
The Future Of CSS
PPTX
PDF
LESS is More
Sass presentation
The Future of CSS
Intro to SASS CSS
Doing More With Less
HTML5, CSS, JavaScript Style guide and coding conventions
Ppt ch05
CSS 開發加速指南-Sass & Compass
LESS, the CSS Preprocessor
CSS3 3D Workshop
Intro to Sass for WordPress Developers
BDUG Responsive Web Theming - 7/23/12
How to use CSS3 in WordPress
How to use CSS3 in WordPress - Sacramento
Sass and compass workshop
Using LESS, the CSS Preprocessor: J and Beyond 2013
Quality Development with CSS3
The Future Of CSS
LESS is More
Ad

Similar to Agile CSS development with Compass and Sass (20)

PDF
Accelerated Stylesheets
PDF
Sass and Compass - Getting Started
PDF
Keep calm and let's play CSS3
PDF
Preprocessor presentation
PDF
LESS : The dynamic stylesheet language
PDF
Mobile-first OOCSS, Sass & Compass at BBC Responsive News
PDF
Getting Started with Sass & Compass
PDF
SASS, Compass, Gulp, Greensock
PDF
CSS Extenders
PDF
Workshop 6: Designer tools
PDF
HTML5 and CSS3 – exploring mobile possibilities - Frontend Conference Zürich
PDF
Sass & Compass (Barcamp Stuttgart 2012)
PDF
Big Design Conference: CSS3
PDF
HTML5 and CSS3 – exploring mobile possibilities - Dynabyte event
KEY
Advanced sass/compass
KEY
Bringing sexy back to CSS: SASS/SCSS, LESS and Compass
PDF
CSS Less framework overview, Pros and Cons
PPTX
Raleigh Web Design Meetup Group - Sass Presentation
PDF
CSS3 Transforms Transitions and Animations
PDF
Css3 and gwt in perfect harmony
Accelerated Stylesheets
Sass and Compass - Getting Started
Keep calm and let's play CSS3
Preprocessor presentation
LESS : The dynamic stylesheet language
Mobile-first OOCSS, Sass & Compass at BBC Responsive News
Getting Started with Sass & Compass
SASS, Compass, Gulp, Greensock
CSS Extenders
Workshop 6: Designer tools
HTML5 and CSS3 – exploring mobile possibilities - Frontend Conference Zürich
Sass & Compass (Barcamp Stuttgart 2012)
Big Design Conference: CSS3
HTML5 and CSS3 – exploring mobile possibilities - Dynabyte event
Advanced sass/compass
Bringing sexy back to CSS: SASS/SCSS, LESS and Compass
CSS Less framework overview, Pros and Cons
Raleigh Web Design Meetup Group - Sass Presentation
CSS3 Transforms Transitions and Animations
Css3 and gwt in perfect harmony
Ad

More from Andrea Verlicchi (7)

PDF
How and Why ($) to improve web performance.pdf
PDF
Come e perché ($) migliorare le prestazioni web.pdf
PPTX
Come e perché ($) migliorare le prestazioni web - Aprile 2023.pptx
PDF
2022.04 - CSS Day IT - Images Optimisation 4.0
PDF
Responsive images, an html 5.1 standard
PDF
Sviluppo CSS agile con SASS e Compass - CSS Day 2015 Faenza
PDF
Css3 transitions and animations + graceful degradation with jQuery
How and Why ($) to improve web performance.pdf
Come e perché ($) migliorare le prestazioni web.pdf
Come e perché ($) migliorare le prestazioni web - Aprile 2023.pptx
2022.04 - CSS Day IT - Images Optimisation 4.0
Responsive images, an html 5.1 standard
Sviluppo CSS agile con SASS e Compass - CSS Day 2015 Faenza
Css3 transitions and animations + graceful degradation with jQuery

Recently uploaded (20)

PDF
RPKI Status Update, presented by Makito Lay at IDNOG 10
PPTX
CHE NAA, , b,mn,mblblblbljb jb jlb ,j , ,C PPT.pptx
PPTX
INTERNET------BASICS-------UPDATED PPT PRESENTATION
PPTX
Introuction about WHO-FIC in ICD-10.pptx
PPTX
PptxGenJS_Demo_Chart_20250317130215833.pptx
PDF
Paper PDF World Game (s) Great Redesign.pdf
PPTX
Introduction about ICD -10 and ICD11 on 5.8.25.pptx
PDF
The New Creative Director: How AI Tools for Social Media Content Creation Are...
PDF
WebRTC in SignalWire - troubleshooting media negotiation
PPTX
presentation_pfe-universite-molay-seltan.pptx
PDF
Tenda Login Guide: Access Your Router in 5 Easy Steps
PPTX
Job_Card_System_Styled_lorem_ipsum_.pptx
PPT
Design_with_Watersergyerge45hrbgre4top (1).ppt
PPTX
artificial intelligence overview of it and more
PPTX
SAP Ariba Sourcing PPT for learning material
PDF
An introduction to the IFRS (ISSB) Stndards.pdf
PPTX
Digital Literacy And Online Safety on internet
PPTX
international classification of diseases ICD-10 review PPT.pptx
PPTX
Funds Management Learning Material for Beg
PPTX
Module 1 - Cyber Law and Ethics 101.pptx
RPKI Status Update, presented by Makito Lay at IDNOG 10
CHE NAA, , b,mn,mblblblbljb jb jlb ,j , ,C PPT.pptx
INTERNET------BASICS-------UPDATED PPT PRESENTATION
Introuction about WHO-FIC in ICD-10.pptx
PptxGenJS_Demo_Chart_20250317130215833.pptx
Paper PDF World Game (s) Great Redesign.pdf
Introduction about ICD -10 and ICD11 on 5.8.25.pptx
The New Creative Director: How AI Tools for Social Media Content Creation Are...
WebRTC in SignalWire - troubleshooting media negotiation
presentation_pfe-universite-molay-seltan.pptx
Tenda Login Guide: Access Your Router in 5 Easy Steps
Job_Card_System_Styled_lorem_ipsum_.pptx
Design_with_Watersergyerge45hrbgre4top (1).ppt
artificial intelligence overview of it and more
SAP Ariba Sourcing PPT for learning material
An introduction to the IFRS (ISSB) Stndards.pdf
Digital Literacy And Online Safety on internet
international classification of diseases ICD-10 review PPT.pptx
Funds Management Learning Material for Beg
Module 1 - Cyber Law and Ethics 101.pptx

Agile CSS development with Compass and Sass

  • 1. YOOXlabs ~ 22.09.2015 andreaverlicchi.eu ~ @verlok ~ #YOOXlabsTechEvent Agile CSS Development with Compass / SASS
  • 2. • Strong addiction to front-end development • Front-end Architect • Occasional speaker andreaverlicchi.eu ~ @verlok ~ #YOOXlabsTechEvent
  • 3. YOOXlabs Tech Event Front-End Development October 2015
  • 10. Sass is the most mature, stable, and powerful professional grade CSS extension language in the world.
  • 11. How it works: locally FILE .SCSS FILE .CSS WATCHGRUNT
  • 12. How it works: CI FILE .SCSS COMPILE FILE .CSS
  • 13. button { background: #ABCDEF; } a { color: #ABCDEF; } header { border-bottom: 5px; border-color: #ABCDEF; } $mainColor: #ABCDEF; button { background: $mainColor; } a { color: $mainColor; } header { border-bottom: 5px; border-color: $mainColor; } Variables
  • 14. Nesting article h1 { margin-right: 1em; } article a { color: white; background: red; display: block; } article a:hover { color: red; background: white; } article { h1 { margin-right: 1em; } a { color: white; background: red; display: block; &:hover { color: red; background: white; } } }
  • 15. Math aside { width: 23.95833%; } $width: 960px; $asideWidth: 230px; aside { width: $asideWidth / $width * 100%; }
  • 16. Partials @import “_variables”; @import "_reset"; @import "_fonts"; @import "_headerFooter"; @import "_forms"; @import "_base"; @import "_helpers"; @import “_whatever”; … main.scss main.css // _reset.scss html, body, div, span, h1, h2, h3, h4, h5, h6 … { margin: 0; padding: 0; … } // … // _fonts.scss @font-face { font-family: myFont; //… } // … // … // _whatever.scss
  • 17. Helpers button:hover { background-color:
 #A6CDF4; } button.disabled { background-color:
 #C4CDD6; } $buttonColor: #ABCDEF; button:hover { background-color: 
 adjust-saturation($buttonColor, 10%); } button.disabled { background-color: 
 adjust-saturation($buttonColor, -10%); }
  • 18. Extend .message { font-weight: bold; padding: 1em; border-width: 2px; } .error { @extend .message; color: red; border-color: red; } .alert { @extend .message; color: orange; border-color: orange; } .message, .error, .alert { font-weight: bold; padding: 1em; border-width: 2px; } .error { color: red; border-color: red; } .alert { color: orange; border-color: orange; }
  • 19. Extend %message { font-weight: bold; padding: 1em; border-width: 2px; } .error { @extend %message; color: red; border-color: red; } .alert { @extend %message; color: orange; border-color: orange; } .error, .alert { font-weight: bold; padding: 1em; border-width: 2px; } .error { color: red; border-color: red; } .alert { color: orange; border-color: orange; }
  • 20. Mixins @mixin message { font-weight: bold; padding: 1em; border-width: 2px; } .error { @include message; color: red; border-color: red; } .alert { @include message; color: orange; border-color: orange; } .error { font-weight: bold; padding: 1em; border-width: 2px; color: red; border-color: red; } .alert { font-weight: bold; padding: 1em; border-width: 2px; color: orange; border-color: orange; }
  • 21. Extend vs Mixins • CSS length • Usage with media queries • Parameters EXTEND WINS MIXIN WINS MIXIN WINS
  • 22. Mixins @mixin opacity($opacity) { opacity: $opacity; filter: alpha(opacity=$opacity*100); } .faded-text { @include opacity(0.8); } .faded-text { opacity: 0.8; filter: alpha(opacity=80); }
  • 23. Output style • nested .widget-social { text-align: right; } .widget-social a, .widget-social a:visited { padding: 0 3px; color: #222222; } .widget-social a:hover { color: #B00909; }
  • 24. Output style • nested • expanded .widget-social { text-align: right; } .widget-social a, .widget-social a:visited { padding: 0 3px; color: #222222; } .widget-social a:hover { color: #B00909; }
  • 25. Output style • nested • expanded • compact .widget-social { text-align: right; } .widget-social a, .widget-social a:visited { padding: 0 3px; … } .widget-social a:hover { color: #B00909; }
  • 26. Output style • nested • expanded • compact • compressed .widget-social{text-align:right}.widget-social a,.widget-social a:visited{padding:0 3px;color:#222222}.widget-social a:hover{co lor:#B00909}
  • 27. Debug • source maps • line comments
  • 28. SASS • Variables • Nesting • Math • Partials • Extend • Mixins
  • 29. Compass is an open-source CSS Authoring Framework. Compass uses SASS.
  • 31. Thresholds configuration // Dichiarare prima di @import-are compass $graceful-usage-threshold: 5; // def: 0.1 $critical-usage-threshold: 1; // def: 0.01 @import "compass/css3"; // Tutto il resto a seguire...
  • 33. Background & Gradients .myBox { @include background(linear-gradient(to bottom, #F00, #0F0)); } .myBox { // ... background: -moz-linear-gradient(top, #ff0000, #00ff00); background: -webkit-linear-gradient(top, #ff0000, #00ff00); background: linear-gradient(to bottom, #ff0000, #00ff00); }
  • 34. Keyframes @include keyframes(spin) { from { transform: rotate(0); } to { transform: rotate(360deg); } } @-moz-keyframes spin { ... } @-webkit-keyframes spin { ... } @keyframes spin { from { transform: rotate(0); } to { transform: rotate(360deg); } }
  • 35. Animation .myBox { @include animation(spin 1s); } .myBox { -moz-animation: spin 1s; -webkit-animation: spin 1s; animation: spin 1s; }
  • 36. Flexbox .parent { @include display-flex; @include flex-wrap(wrap); } .child { @include flex-grow(1); } .parent { display: -webkit-flex; display: flex; -webkit-flex-wrap: wrap; flex-wrap: wrap; } .child { -webkit-flex-grow: 1; flex-grow: 1; }
  • 39. Sprites - All @import “compass/utilities/sprites"; @import "flags/*.png"; @include all-flags-sprites; .flags-it, .flags-de, .flags-fr { background: url('/images/flags-s34fe0604ab.png') no-repeat; } .flags-it { background-position: 0 0; } .flags-de { background-position: 0 -32px; } .flags-fr { background-position: 0 -64px; } // flags // it.png // de.png // fr.png
  • 40. Sprite - Single @import "compass/utilities/sprites"; @import "flags/*.png"; // it.png // de.png .myBox { @include flags-sprite(it); } .anotherBox { @include flags-sprite(de); } .myBox, .anotherBox { background: url('../img/flags- s69e070e3f8.png') no-repeat; } .myBox { background-position: 0 0; } .anotherBox { background-position: 0 -32px; }
  • 41. Sprite - Advanced • Box size generation • Offset inside the box • Sprite images spacing • Display density management • Here’s how:
 andreaverlicchi.eu/yooxlabs-2015-09/
  • 42. Installation • Download Ruby
 rubyinstaller.org • Install Compass • Download Ruby
 ruby-lang.com • Install Compass gem install compasssudo
  • 43. Configuration • Activate the project folder • Create the configuration file cd path/to/project compass config --css-dir css
  • 44. Primi file SASS • Convert CSS to SCSS sass-convert css/main.css --to scss • Create initial folders and files compass install compass sass-convert css --to scss --recursive
  • 45. Usage • Compile compass compile • Start the watcher compass watch
  • 46. Compass • Sprite • Browser thresholds • Included mixins
  • 47. • Project organization • Development speed • Maintain with ease
  • 50. SASS vs LESS @verlok ~ #YOOXlabsTechEvent https://css-tricks.com/sass-vs-less/ http://www.zingdesign.com/less-vs-sass-its-time-to- switch-to-sass/