Top Banner
YOOXlabs ~ 22.09.2015 andreaverlicchi.eu ~ @verlok ~ #YOOXlabsTechEvent Agile CSS Development with Compass / SASS
50

Agile CSS development with Compass and Sass

Apr 14, 2017

Download

Internet

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Agile CSS development with Compass and Sass

YOOXlabs ~ 22.09.2015

andreaverlicchi.eu ~ @verlok ~ #YOOXlabsTechEvent

Agile CSS Development with Compass / SASS

Page 2: Agile CSS development with Compass and Sass

• Strong addiction tofront-end development

• Front-end Architect

• Occasional speaker

andreaverlicchi.eu ~ @verlok ~ #YOOXlabsTechEvent

Page 3: Agile CSS development with Compass and Sass

YOOXlabs Tech EventFront-End Development

October 2015

Page 4: Agile CSS development with Compass and Sass
Page 5: Agile CSS development with Compass and Sass

Language

Page 6: Agile CSS development with Compass and Sass

Repetitive

Page 7: Agile CSS development with Compass and Sass

Length

Page 8: Agile CSS development with Compass and Sass

Mess?

Page 9: Agile CSS development with Compass and Sass

Maintenance

Page 10: Agile CSS development with Compass and Sass

Sass is the most mature, stable, and powerful professional grade CSS extension language in the world.

Page 11: Agile CSS development with Compass and Sass

How it works: locally

FILE .SCSS

FILE .CSS

WATCHGRUNT

Page 12: Agile CSS development with Compass and Sass

How it works: CI

FILE .SCSS

COMPILE

FILE .CSS

Page 13: Agile CSS development with Compass and Sass

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

Page 14: Agile CSS development with Compass and Sass

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;

}}

}

Page 15: Agile CSS development with Compass and Sass

Math

aside {width: 23.95833%;

}

$width: 960px;$asideWidth: 230px;

aside { width: $asideWidth / $width * 100%;}

Page 16: Agile CSS development with Compass and Sass

Partials

@import “_variables”;@import "_reset";@import "_fonts";@import "_headerFooter";@import "_forms";@import "_base";@import "_helpers";@import “_whatever”;

main.scss main.css

// _reset.scsshtml, body, div, span, h1, h2, h3, h4, h5, h6 … { margin: 0; padding: 0; …} // …

// _fonts.scss@font-face { font-family: myFont; //…} // …

// …// _whatever.scss

Page 17: Agile CSS development with Compass and Sass

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%);

}

Page 18: Agile CSS development with Compass and Sass

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;}

Page 19: Agile CSS development with Compass and Sass

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;}

Page 20: Agile CSS development with Compass and Sass

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;}

Page 21: Agile CSS development with Compass and Sass

Extend vs Mixins

• CSS length

• Usage with media queries

• Parameters

EXTEND WINS

MIXIN WINS

MIXIN WINS

Page 22: Agile CSS development with Compass and Sass

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);}

Page 23: Agile CSS development with Compass and Sass

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; }

Page 24: Agile CSS development with Compass and Sass

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;}

Page 25: Agile CSS development with Compass and Sass

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; }

Page 26: Agile CSS development with Compass and Sass

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}

Page 27: Agile CSS development with Compass and Sass

Debug

• source maps

• line comments

Page 28: Agile CSS development with Compass and Sass

SASS

• Variables

• Nesting

• Math

• Partials

• Extend

• Mixins

Page 29: Agile CSS development with Compass and Sass

Compass is an open-source CSS Authoring Framework. Compass uses SASS.

Page 30: Agile CSS development with Compass and Sass

Browser thresholds

Page 31: Agile CSS development with Compass and Sass

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...

Page 32: Agile CSS development with Compass and Sass

251 included mixing

Page 33: Agile CSS development with Compass and Sass

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);}

Page 34: Agile CSS development with Compass and Sass

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); }}

Page 35: Agile CSS development with Compass and Sass

Animation

.myBox { @include animation(spin 1s);}

.myBox { -moz-animation: spin 1s; -webkit-animation: spin 1s; animation: spin 1s;}

Page 36: Agile CSS development with Compass and Sass

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;}

Page 37: Agile CSS development with Compass and Sass

http://compass-style.org/index/mixins

Page 38: Agile CSS development with Compass and Sass

Sprites

Page 39: Agile CSS development with Compass and Sass

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

Page 40: Agile CSS development with Compass and Sass

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;

}

Page 41: Agile CSS development with Compass and Sass

Sprite - Advanced

• Box size generation

• Offset inside the box

• Sprite images spacing

• Display density management

• Here’s how: andreaverlicchi.eu/yooxlabs-2015-09/

Page 42: Agile CSS development with Compass and Sass

Installation

• Download Ruby rubyinstaller.org

• Install Compass

• Download Ruby ruby-lang.com

• Install Compass

gem install compasssudo

Page 43: Agile CSS development with Compass and Sass

Configuration

• Activate the project folder

• Create the configuration file

cd path/to/project

compass config --css-dir css

Page 44: Agile CSS development with Compass and Sass

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

Page 45: Agile CSS development with Compass and Sass

Usage

• Compile

compass compile

• Start the watcher

compass watch

Page 46: Agile CSS development with Compass and Sass

Compass

• Sprite

• Browser thresholds

• Included mixins

Page 47: Agile CSS development with Compass and Sass

• Project organization

• Development speed

• Maintain with ease

Page 48: Agile CSS development with Compass and Sass
Page 49: Agile CSS development with Compass and Sass

Q&A

@verlok ~ #YOOXlabsTechEvent

Page 50: Agile CSS development with Compass and Sass

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/