SlideShare a Scribd company logo
How to Use Sass
to Make Your Site
More Maintainable
Scott Vandehey - @spaceninja
Front-End Engineer - Puppet Labs
Devsigner 2014
DRY
• Don’t Repeat Yourself
• Every piece of knowledge must have a
single, unambiguous, authoritative
representation within a system.
–Brad Bowman
“Always code as if the guy
who ends up maintaining
your code will be a

violent psychopath

who knows where you live.”
Sass Color Manipulation
$r: #f00; // red
$b: #00f; // blue
p {
color: rgba($r, 0.5); // rgba(255,0,0,.5)
color: mix($r, $b); // returns #7f007f
color: lighten($r, 10%); // returns #ff3333
color: darken($r, 10%); // returns #cc0000
color: complement($r); // returns cyan
color: desaturate($r, 10%); // returns #f20d0d
}
Variables
$brand_green: #76C642;
$brand_font: "PT Sans";
$fontstack: #{$brand_font}, Arial, sans-serif;
!
.btn {
font-family: $fontstack;
background: $brand_green;
}
!
.btn {
font-family: "PT Sans", Arial, sans-serif;
background: #76C642;
}
Rendered Output
Nesting
.btn {
background: $brand_green;
&.orange {
background: $brand_orange;
}
}
!
.btn {
background: #76C642;
}
.btn.orange {
background: #EFA92D;
}
Rendered Output
Includes
// style.scss
// This file combines all partials into one
// style sheet that will be loaded on all pages.
!
@import "vars"; // Variables and mixins.
@import "fonts"; // Custom fonts.
@import "normalize"; // An alternative to CSS resets.
@import "jquery-ui"; // jQuery UI overrides.
@import "drupal"; // Drupal-Specific Styles.
@import "layout"; // Defines overall page layout.
@import "global"; // Styles used on every page.
@import "scoped"; // Styles scoped to individual pages.
@import "home"; // Styles scoped to the homepage.
@import "blog"; // Styles scoped to the blog.
@import "print"; // Styles for printing.
Example Partial
/**
* global.scss - Global Styles
* These styles control the broad strokes of the theme - header, footer, etc.
* These styles should apply to every section of the site.
*/
!
/* Base Colors & Fonts ---------------------------------------------------- */
body {
background: #fff;
color: $main_text_color;
font:16px/1.5 $fontstack;
}
a {
@include single-transition(color, .25s);
text-decoration: none;
color: $link_color;
&:hover, &:focus, &:active {
color: $active_link_color;
text-decoration: underline;
}
}
Extends
%shared_code {
font: 30px “Comic Sans MS”;
color: magenta;
}
p.ugly {
@extend shared_code;
color: green;
}
h1.ugly {
@extend shared_code;
font-size: 120px;
}
!
/* output on next slide */
Extends
!
p.ugly,
h1.ugly {
font: 30px “Comic Sans MS”;
color: magenta;
}
p.ugly {
color: green;
}
h1.ugly {
font-size: 120px;
}
Rendered Output
Mixins
@mixin font-size($sizeValue, $baseline_px: 16){
font-size: ($sizeValue * 1) + px;
font-size: ($sizeValue / $baseline_px) + rem;
}
!
h1 {
@include font-size(36);
}
!
h1 {
font-size: 36px;
font-size: 2.25rem;
}
Rendered Output
Buttons Old
.btn {
background: $puppet_green;
&:hover, &:focus {
background: mix(white, $puppet_green, 10%);
}
&.orange {
background: $puppet_orange;
&:hover, &:focus {
background: mix(white, $puppet_orange, 10%);
}
}
&.purple {
background: $puppet_purple;
&:hover, &:focus {
background: mix(white, $puppet_purple, 10%);
}
}
}
Buttons New
@mixin btn($color: $puppet_green) {
background: $color;
&:hover, &:focus {
background: mix(white, $color, 10%);
}
}
.btn {
@include btn();
&.orange {
@include btn($puppet_orange);
}
&.purple {
@include btn($puppet_purple);
}
}
Modernizr Testing
@mixin yep($feature) { // feature supported
.#{$feature} & {
@content;
}
}
!
@mixin nope($feature) { // feature not supported
.no-#{$feature} & {
@content;
}
}
!
/* usage on next slide */
Modernizr Testing
#logo {
@include yep(svg) {
background: url(logo.svg):
}
@include nope(svg) {
background: url(logo.png):
}
}
!
.svg #logo {
background: url(logo.svg):
}
.no-svg #logo {
background: url(logo.png):
}
Rendered Output
Flexible Columns, Fixed Gutter
@mixin span-columns($columns, $gutter: 20px) {
$gutterWidth: (($columns - 1) * $gutter);
$columnWidth: "(100% - #{$gutterWidth}) / #{$columns}”;
width: calc($columnWidth);
float: left;
margin: 0 $gutter $gutter 0;
@include nope(csscalc) {
// fallback styles for browsers that don't do calc()
}
}
.three-columns .column {
@include span-columns(3);
}
!
.three-columns .column {
width: calc((100% - 40px) / 3);
margin: 0 20px 20px 0;
}
.no-csscalc .three-columns .column { /* fallback styles */ }
!
/* abbreviated for readability. full source: git.io/9vb-Fg */
Rendered Output

More Related Content

Similar to How to Use Sass to Make Your Site More Maintainable

Sass
SassSass
Brian Hoke: WordCamp Toronto 2014 Presentation "Sass & WordPress"
Brian Hoke: WordCamp Toronto 2014 Presentation "Sass & WordPress"Brian Hoke: WordCamp Toronto 2014 Presentation "Sass & WordPress"
Brian Hoke: WordCamp Toronto 2014 Presentation "Sass & WordPress"
bentleyhoke
 
Workshop 6: Designer tools
Workshop 6: Designer toolsWorkshop 6: Designer tools
Workshop 6: Designer tools
Visual Engineering
 
Simple Blue Blog Template XML 的副本
Simple Blue Blog Template XML 的副本Simple Blue Blog Template XML 的副本
Simple Blue Blog Template XML 的副本a5494535
 
A better CSS: Sass and Less - CC FE & UX
A better CSS: Sass and Less - CC FE & UXA better CSS: Sass and Less - CC FE & UX
A better CSS: Sass and Less - CC FE & UX
JWORKS powered by Ordina
 
Sass Essentials
Sass EssentialsSass Essentials
Sass Essentials
romiguelangel
 
Sass - Making CSS fun again.
Sass - Making CSS fun again.Sass - Making CSS fun again.
Sass - Making CSS fun again.
Gabriel Neutzling
 
Wrangling the CSS Beast with Sass
Wrangling the CSS Beast  with SassWrangling the CSS Beast  with Sass
Wrangling the CSS Beast with Sass
Rob Friesel
 
Mobile-first OOCSS, Sass & Compass at BBC Responsive News
Mobile-first OOCSS, Sass & Compass at BBC Responsive NewsMobile-first OOCSS, Sass & Compass at BBC Responsive News
Mobile-first OOCSS, Sass & Compass at BBC Responsive NewsKaelig Deloumeau-Prigent
 
Finding the sassy in sass
Finding the sassy in sassFinding the sassy in sass
Finding the sassy in sass
Tudor Barbu
 
CSS'in Gücü Adına
CSS'in Gücü AdınaCSS'in Gücü Adına
CSS'in Gücü Adına
Adem Ilter
 
Doing more with LESS
Doing more with LESSDoing more with LESS
Doing more with LESS
jsmith92
 
Theming and Sass
Theming and SassTheming and Sass
Theming and Sass
James Pearce
 
CSS Extenders
CSS ExtendersCSS Extenders
CSS Extenders
Idan Gazit
 
One Sass File, So Many Sites
One Sass File, So Many SitesOne Sass File, So Many Sites
One Sass File, So Many Sites
Mina Markham
 
LESS is More
LESS is MoreLESS is More
LESS is Morejsmith92
 
Sass & Compass (Barcamp Stuttgart 2012)
Sass & Compass (Barcamp Stuttgart 2012)Sass & Compass (Barcamp Stuttgart 2012)
Sass & Compass (Barcamp Stuttgart 2012)
emrox
 
Getting Started with Sass & Compass
Getting Started with Sass & CompassGetting Started with Sass & Compass
Getting Started with Sass & Compass
Rob Davarnia
 
Preprocessor presentation
Preprocessor presentationPreprocessor presentation
Preprocessor presentation
Mario Noble
 

Similar to How to Use Sass to Make Your Site More Maintainable (20)

Sass
SassSass
Sass
 
Brian Hoke: WordCamp Toronto 2014 Presentation "Sass & WordPress"
Brian Hoke: WordCamp Toronto 2014 Presentation "Sass & WordPress"Brian Hoke: WordCamp Toronto 2014 Presentation "Sass & WordPress"
Brian Hoke: WordCamp Toronto 2014 Presentation "Sass & WordPress"
 
Workshop 6: Designer tools
Workshop 6: Designer toolsWorkshop 6: Designer tools
Workshop 6: Designer tools
 
Simple Blue Blog Template XML 的副本
Simple Blue Blog Template XML 的副本Simple Blue Blog Template XML 的副本
Simple Blue Blog Template XML 的副本
 
A better CSS: Sass and Less - CC FE & UX
A better CSS: Sass and Less - CC FE & UXA better CSS: Sass and Less - CC FE & UX
A better CSS: Sass and Less - CC FE & UX
 
Sass Essentials
Sass EssentialsSass Essentials
Sass Essentials
 
Sass - Making CSS fun again.
Sass - Making CSS fun again.Sass - Making CSS fun again.
Sass - Making CSS fun again.
 
FCIP SASS Talk
FCIP SASS TalkFCIP SASS Talk
FCIP SASS Talk
 
Wrangling the CSS Beast with Sass
Wrangling the CSS Beast  with SassWrangling the CSS Beast  with Sass
Wrangling the CSS Beast with Sass
 
Mobile-first OOCSS, Sass & Compass at BBC Responsive News
Mobile-first OOCSS, Sass & Compass at BBC Responsive NewsMobile-first OOCSS, Sass & Compass at BBC Responsive News
Mobile-first OOCSS, Sass & Compass at BBC Responsive News
 
Finding the sassy in sass
Finding the sassy in sassFinding the sassy in sass
Finding the sassy in sass
 
CSS'in Gücü Adına
CSS'in Gücü AdınaCSS'in Gücü Adına
CSS'in Gücü Adına
 
Doing more with LESS
Doing more with LESSDoing more with LESS
Doing more with LESS
 
Theming and Sass
Theming and SassTheming and Sass
Theming and Sass
 
CSS Extenders
CSS ExtendersCSS Extenders
CSS Extenders
 
One Sass File, So Many Sites
One Sass File, So Many SitesOne Sass File, So Many Sites
One Sass File, So Many Sites
 
LESS is More
LESS is MoreLESS is More
LESS is More
 
Sass & Compass (Barcamp Stuttgart 2012)
Sass & Compass (Barcamp Stuttgart 2012)Sass & Compass (Barcamp Stuttgart 2012)
Sass & Compass (Barcamp Stuttgart 2012)
 
Getting Started with Sass & Compass
Getting Started with Sass & CompassGetting Started with Sass & Compass
Getting Started with Sass & Compass
 
Preprocessor presentation
Preprocessor presentationPreprocessor presentation
Preprocessor presentation
 

Recently uploaded

guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...
Rogerio Filho
 
test test test test testtest test testtest test testtest test testtest test ...
test test  test test testtest test testtest test testtest test testtest test ...test test  test test testtest test testtest test testtest test testtest test ...
test test test test testtest test testtest test testtest test testtest test ...
Arif0071
 
Latest trends in computer networking.pptx
Latest trends in computer networking.pptxLatest trends in computer networking.pptx
Latest trends in computer networking.pptx
JungkooksNonexistent
 
Meet up Milano 14 _ Axpo Italia_ Migration from Mule3 (On-prem) to.pdf
Meet up Milano 14 _ Axpo Italia_ Migration from Mule3 (On-prem) to.pdfMeet up Milano 14 _ Axpo Italia_ Migration from Mule3 (On-prem) to.pdf
Meet up Milano 14 _ Axpo Italia_ Migration from Mule3 (On-prem) to.pdf
Florence Consulting
 
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
ufdana
 
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
eutxy
 
Internet of Things in Manufacturing: Revolutionizing Efficiency & Quality | C...
Internet of Things in Manufacturing: Revolutionizing Efficiency & Quality | C...Internet of Things in Manufacturing: Revolutionizing Efficiency & Quality | C...
Internet of Things in Manufacturing: Revolutionizing Efficiency & Quality | C...
CIOWomenMagazine
 
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
3ipehhoa
 
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
keoku
 
1.Wireless Communication System_Wireless communication is a broad term that i...
1.Wireless Communication System_Wireless communication is a broad term that i...1.Wireless Communication System_Wireless communication is a broad term that i...
1.Wireless Communication System_Wireless communication is a broad term that i...
JeyaPerumal1
 
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
3ipehhoa
 
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdfJAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
Javier Lasa
 
Bài tập unit 1 English in the world.docx
Bài tập unit 1 English in the world.docxBài tập unit 1 English in the world.docx
Bài tập unit 1 English in the world.docx
nhiyenphan2005
 
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
3ipehhoa
 
Comptia N+ Standard Networking lesson guide
Comptia N+ Standard Networking lesson guideComptia N+ Standard Networking lesson guide
Comptia N+ Standard Networking lesson guide
GTProductions1
 
Italy Agriculture Equipment Market Outlook to 2027
Italy Agriculture Equipment Market Outlook to 2027Italy Agriculture Equipment Market Outlook to 2027
Italy Agriculture Equipment Market Outlook to 2027
harveenkaur52
 
How to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptxHow to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptx
Gal Baras
 
This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!
nirahealhty
 
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptxBridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Brad Spiegel Macon GA
 
The+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptxThe+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptx
laozhuseo02
 

Recently uploaded (20)

guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...
 
test test test test testtest test testtest test testtest test testtest test ...
test test  test test testtest test testtest test testtest test testtest test ...test test  test test testtest test testtest test testtest test testtest test ...
test test test test testtest test testtest test testtest test testtest test ...
 
Latest trends in computer networking.pptx
Latest trends in computer networking.pptxLatest trends in computer networking.pptx
Latest trends in computer networking.pptx
 
Meet up Milano 14 _ Axpo Italia_ Migration from Mule3 (On-prem) to.pdf
Meet up Milano 14 _ Axpo Italia_ Migration from Mule3 (On-prem) to.pdfMeet up Milano 14 _ Axpo Italia_ Migration from Mule3 (On-prem) to.pdf
Meet up Milano 14 _ Axpo Italia_ Migration from Mule3 (On-prem) to.pdf
 
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
 
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
 
Internet of Things in Manufacturing: Revolutionizing Efficiency & Quality | C...
Internet of Things in Manufacturing: Revolutionizing Efficiency & Quality | C...Internet of Things in Manufacturing: Revolutionizing Efficiency & Quality | C...
Internet of Things in Manufacturing: Revolutionizing Efficiency & Quality | C...
 
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
 
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
 
1.Wireless Communication System_Wireless communication is a broad term that i...
1.Wireless Communication System_Wireless communication is a broad term that i...1.Wireless Communication System_Wireless communication is a broad term that i...
1.Wireless Communication System_Wireless communication is a broad term that i...
 
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
 
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdfJAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
 
Bài tập unit 1 English in the world.docx
Bài tập unit 1 English in the world.docxBài tập unit 1 English in the world.docx
Bài tập unit 1 English in the world.docx
 
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
 
Comptia N+ Standard Networking lesson guide
Comptia N+ Standard Networking lesson guideComptia N+ Standard Networking lesson guide
Comptia N+ Standard Networking lesson guide
 
Italy Agriculture Equipment Market Outlook to 2027
Italy Agriculture Equipment Market Outlook to 2027Italy Agriculture Equipment Market Outlook to 2027
Italy Agriculture Equipment Market Outlook to 2027
 
How to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptxHow to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptx
 
This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!
 
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptxBridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
 
The+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptxThe+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptx
 

How to Use Sass to Make Your Site More Maintainable

  • 1. How to Use Sass to Make Your Site More Maintainable Scott Vandehey - @spaceninja Front-End Engineer - Puppet Labs Devsigner 2014
  • 2. DRY • Don’t Repeat Yourself • Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
  • 3. –Brad Bowman “Always code as if the guy who ends up maintaining your code will be a
 violent psychopath
 who knows where you live.”
  • 4. Sass Color Manipulation $r: #f00; // red $b: #00f; // blue p { color: rgba($r, 0.5); // rgba(255,0,0,.5) color: mix($r, $b); // returns #7f007f color: lighten($r, 10%); // returns #ff3333 color: darken($r, 10%); // returns #cc0000 color: complement($r); // returns cyan color: desaturate($r, 10%); // returns #f20d0d }
  • 5. Variables $brand_green: #76C642; $brand_font: "PT Sans"; $fontstack: #{$brand_font}, Arial, sans-serif; ! .btn { font-family: $fontstack; background: $brand_green; } ! .btn { font-family: "PT Sans", Arial, sans-serif; background: #76C642; } Rendered Output
  • 6. Nesting .btn { background: $brand_green; &.orange { background: $brand_orange; } } ! .btn { background: #76C642; } .btn.orange { background: #EFA92D; } Rendered Output
  • 7. Includes // style.scss // This file combines all partials into one // style sheet that will be loaded on all pages. ! @import "vars"; // Variables and mixins. @import "fonts"; // Custom fonts. @import "normalize"; // An alternative to CSS resets. @import "jquery-ui"; // jQuery UI overrides. @import "drupal"; // Drupal-Specific Styles. @import "layout"; // Defines overall page layout. @import "global"; // Styles used on every page. @import "scoped"; // Styles scoped to individual pages. @import "home"; // Styles scoped to the homepage. @import "blog"; // Styles scoped to the blog. @import "print"; // Styles for printing.
  • 8. Example Partial /** * global.scss - Global Styles * These styles control the broad strokes of the theme - header, footer, etc. * These styles should apply to every section of the site. */ ! /* Base Colors & Fonts ---------------------------------------------------- */ body { background: #fff; color: $main_text_color; font:16px/1.5 $fontstack; } a { @include single-transition(color, .25s); text-decoration: none; color: $link_color; &:hover, &:focus, &:active { color: $active_link_color; text-decoration: underline; } }
  • 9. Extends %shared_code { font: 30px “Comic Sans MS”; color: magenta; } p.ugly { @extend shared_code; color: green; } h1.ugly { @extend shared_code; font-size: 120px; } ! /* output on next slide */
  • 10. Extends ! p.ugly, h1.ugly { font: 30px “Comic Sans MS”; color: magenta; } p.ugly { color: green; } h1.ugly { font-size: 120px; } Rendered Output
  • 11. Mixins @mixin font-size($sizeValue, $baseline_px: 16){ font-size: ($sizeValue * 1) + px; font-size: ($sizeValue / $baseline_px) + rem; } ! h1 { @include font-size(36); } ! h1 { font-size: 36px; font-size: 2.25rem; } Rendered Output
  • 12. Buttons Old .btn { background: $puppet_green; &:hover, &:focus { background: mix(white, $puppet_green, 10%); } &.orange { background: $puppet_orange; &:hover, &:focus { background: mix(white, $puppet_orange, 10%); } } &.purple { background: $puppet_purple; &:hover, &:focus { background: mix(white, $puppet_purple, 10%); } } }
  • 13. Buttons New @mixin btn($color: $puppet_green) { background: $color; &:hover, &:focus { background: mix(white, $color, 10%); } } .btn { @include btn(); &.orange { @include btn($puppet_orange); } &.purple { @include btn($puppet_purple); } }
  • 14. Modernizr Testing @mixin yep($feature) { // feature supported .#{$feature} & { @content; } } ! @mixin nope($feature) { // feature not supported .no-#{$feature} & { @content; } } ! /* usage on next slide */
  • 15. Modernizr Testing #logo { @include yep(svg) { background: url(logo.svg): } @include nope(svg) { background: url(logo.png): } } ! .svg #logo { background: url(logo.svg): } .no-svg #logo { background: url(logo.png): } Rendered Output
  • 16. Flexible Columns, Fixed Gutter @mixin span-columns($columns, $gutter: 20px) { $gutterWidth: (($columns - 1) * $gutter); $columnWidth: "(100% - #{$gutterWidth}) / #{$columns}”; width: calc($columnWidth); float: left; margin: 0 $gutter $gutter 0; @include nope(csscalc) { // fallback styles for browsers that don't do calc() } } .three-columns .column { @include span-columns(3); } ! .three-columns .column { width: calc((100% - 40px) / 3); margin: 0 20px 20px 0; } .no-csscalc .three-columns .column { /* fallback styles */ } ! /* abbreviated for readability. full source: git.io/9vb-Fg */ Rendered Output