Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Untangle your stylesheets with Sass
Search
Roy Tomeij
October 15, 2012
Programming
8
900
Untangle your stylesheets with Sass
As presented at FOWA London, FOWA Prague, Kings of Code and CodeConnexx.
Roy Tomeij
October 15, 2012
Tweet
Share
More Decks by Roy Tomeij
See All by Roy Tomeij
Empathy through Acting
roy
1
120
What (Not) to Do
roy
0
96
You and the Big Stage
roy
0
74
Future of Preprocessors
roy
0
170
Make Them Click
roy
0
290
0 to 80 in 40 Minutes
roy
2
250
The Future of CSS Isn't CSS
roy
5
1.1k
Sass: With Great Power Comes Great Responsibility
roy
0
390
Front-End: Fun, Not Frustration
roy
1
1.1k
Other Decks in Programming
See All in Programming
チームの境界をブチ抜いていけ
tokai235
0
210
CSC509 Lecture 08
javiergs
PRO
0
230
Pythonに漸進的に型をつける
nealle
1
110
All About Angular's New Signal Forms
manfredsteyer
PRO
0
200
タスクの特性や不確実性に応じた最適な作業スタイルの選択(ペアプロ・モブプロ・ソロプロ)と実践 / Optimal Work Style Selection: Pair, Mob, or Solo Programming.
honyanya
3
190
オープンソースソフトウェアへの解像度🔬
utam0k
17
3.1k
EMこそClaude Codeでコード調査しよう
shibayu36
0
320
コード生成なしでモック処理を実現!ovechkin-dm/mockioで学ぶメタプログラミング
qualiarts
0
240
CSC305 Lecture 10
javiergs
PRO
0
220
Things You Thought You Didn’t Need To Care About That Have a Big Impact On Your Job
hollycummins
0
250
コードとあなたと私の距離 / The Distance Between Code, You, and I
hiro_y
0
190
XP, Testing and ninja testing ZOZ5
m_seki
3
790
Featured
See All Featured
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
16k
A Tale of Four Properties
chriscoyier
161
23k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
285
14k
Building Adaptive Systems
keathley
44
2.8k
Designing Experiences People Love
moore
142
24k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
30
2.9k
The Pragmatic Product Professional
lauravandoore
36
7k
Writing Fast Ruby
sferik
629
62k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
9
920
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
34
2.3k
Keith and Marios Guide to Fast Websites
keithpitt
411
23k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
253
22k
Transcript
Untangle your stylesheets untangle your stylesheets Roy Tomeij / @roy,
80beans
writing CSS isn’t fun
None
today’s lesson
back to basics
it’s just CSS
two syntaxes: SCSS & Sass .scss { width: 100%; }
.sass width: 100% SCSS Sass
variables $full-width: 100%; .foo { width: $full-width; } .foo {
width: 100%; } Sass CSS
nested rules .foo { width: 100%; a { color: #fff;
} } .foo { width: 100%; } .foo a { color: #fff; } Sass CSS
parent reference .foo { color: #000; &:hover { color: #fff;
} } .foo { color: #000; } .foo:hover { color: #fff; } Sass CSS
mixins @mixin hide-text { text-indent: -999px; overflow: hidden; } .foo
{ width: 100%; @include hide-text; } .foo { width: 100%; text-indent: -999px; overflow: hidden; } Sass CSS
selector inheritance .error { color: red; } .bad-error { @extend
.error; font-weight: bold; } .error, .bad-error { color: red; } .bad-error { font-weight: bold; } CSS Sass
data types $number: 1; $string: "Some string"; $color: blue; $color:
rgba(#f0f, 0.5); // Sass gets this! $boolean: true; $list: facebook, twitter, youtube;
operations $column: 10px; .foo { width: 10px + 2px; width:
2in + 8pt; width: $column / 2; } .foo { width: 12px; width: 2.11111in; width: 5px; } CSS Sass
None
control directives $network: linkedin; .foo { @if $network == twitter
{ background: blue; } @else if $network == youtube { background: red; } @else { background: magenta; } } Sass
control directives .foo { background: magenta; } CSS
control directives @each $network in twitter, facebook, youtube { .icon-#{$network}
{ background: url("#{$network}.png"); } } Sass
control directives .icon-twitter { background: url('twitter.png'); } .icon-facebook { background:
url('facebook.png'); } .icon-youtube { background: url('youtube.png'); } CSS
media queries h1 { width: 500px; @media (…) { width:
400px; } } h1 { width: 500px; } @media (…) { h1 { width: 400px; } } CSS Sass
shiny new features
placeholder selector %error { color: red; } .bad-error { @extend
%error; font-weight: bold; } .bad-error { color: red; } .bad-error { font-weight: bold; } CSS Sass
@content directive @mixin ie6 { * html { @content; }
} @include ie6 { .foo { color: red; } } * html .foo { color: red; } CSS Sass
let’s get creative
retina mixin @mixin retina { @media (min--moz-device-pixel-ratio: 1.5), (-o-min-device-pixel-ratio: 3/2),
(-webkit-min-device-pixel-ratio: 1.5), (min-resolution: 1.5dppx) { @content; } } Sass
retina mixin h1 { background: url("image.png"); @include retina { background:
url("
[email protected]
"); } } Sass
retina mixin h1 { background: url('image.png'); } @media (min--moz-device-pixel-ratio: 1.5),
… { h1 { background: url('
[email protected]
'); } } CSS
making stuff fit
breakpoint media queries @mixin respond-to($device) { @if $device == tablet-portrait
{ @media (max-width: 768px) { @content; } } @else if ($device == phone-portrait) { @media (max-width: 320px) { @content; } } } Sass
breakpoint media queries h1 { width: 600px; @include respond-to(tablet-portrait) {
width: 100%; } @include respond-to(phone-portrait) { width: 200px; } } Sass
breakpoint media queries h1 { width: 600px; } @media (max-width:
768px) { h1 { width: 100%; } } … CSS
inline images .facebook { background: inline-image("facebook.png"); } .facebook { background:
url('data:image/png;base64,…'); } CSS Sass + Compass
inline images %facebook { background: inline-image("facebook.png"); } … CSS Sass
+ Compass
things you may not know
!comments /* Nothing... */ /*! Copyright 2012 */ /* Copyright
2012 */ CSS Sass
variable arguments @mixin foo($args...) { // $args is now a
list! } h1 { @include foo(#000, #fff, #ddd); } Sass
nested @import .foo { color: red; } somefile.sass
nested @import h1 { @import “somefile.sass”; } CSS h1 .foo
{ color: red; } Sass
questions? @roy
thanks shorpy.com! for the awesome pictures