On Github taupecat / sass-rwd
The Tools You Need to Know About
I'm learning how RWD and Sass are a perfect fit with @taupecat at #WCHRVA!
http://rwjf.org (2011)
.column_33 .dog-eared { padding: 24px 8%; /* 24px / 300px */ } @media all and (max-width: 620px) { .column_33 .dog-eared { padding: 24px 3.870967741935%; /* 24px / 620px */ } }
http://nscorp.com (2013)
target / context = result (%)
Built-in function: percentage(target / context)
Percentage returns a unitless number, expressed as a percentage.
.main-content { width: percentage(585px / 960px); } .sidebar { width: percentage(350px / 960px); }
.main-content { width: 60.9375%; } .sidebar { width: 36.45833%; }
Code becomes self-documenting.
Hold that thought…
This is the awesome sauce that makes responsive web design soooo much easier.
.sidebar { background-color: #e5e5e5; font-size: 1.2em; @media all and (min-width: 43.125em) { // 690px / 16px float: left; width: percentage(400px / 1280px); } }
.sidebar { background-color: #e5e5e5; font-size: 1.2em; } @media all and (min-width: 43.125em) { .sidebar { float: left; width: 31.25%; } }
$default-browser-context: 16px !default; @function em($target, $context: $default-browser-context) { @return $target / $context * 1em; } $bp-medium: em(690px); .sidebar { background-color: #e5e5e5; font-size: 1.2em; @media all and (min-width: $bp-medium) { float: left; width: percentage(400px / 1280px); } }
.sidebar { background-color: #e5e5e5; font-size: 1.2em; } @media all and (min-width: 43.125em) { .sidebar { float: left; width: 31.25%; } }
$default-browser-context: 16px !default; @function em($target, $context: $default-browser-context) { @return $target / $context * 1em; } $bp-medium: em(690px); @mixin bp($breakpoint) { @if $breakpoint == medium { @media all and (min-width: $bp-medium) { @content; } } } .sidebar { background-color: #e5e5e5; font-size: 1.2em; @include bp(medium) { float: left; width: percentage(400px / 1280px); } }
Credit: css-tricks.com
.sidebar { background-color: #e5e5e5; font-size: 1.2em; } @media all and (min-width: 43.125em) { .sidebar { float: left; width: 31.25%; } }
@mixin hidpi($media: all) { @media only #{$media} and (min--moz-device-pixel-ratio: 1.5), only #{$media} and (-webkit-min-device-pixel-ratio: 1.5), only #{$media} and (min-resolution: 144dpi), only #{$media} and (min-resolution: 1.5dppx) { @content; } }
“But won't repeated media queries bloat my CSS?”
Lets you aggregate your classes around a set of common properties.
%clearfix { &:before, &:after { content: ""; display: table; } &:after { clear: both; } } .site-header { @extend %clearfix; background-color: #1fbbe3; } .site-footer { @extend %clearfix; background-color: #757b82; }
.site-header:before, .site-header:after, .site-footer:before, .site-footer:after { content: ""; display: table; } .site-header:after, .site-footer:after { clear: both; } .site-header { background-color: #1fbbe3; } .site-footer { background-color: #757b82; }
Doesn't work in @media queries:
.site-header { background-color: #1fbbe3; @include bp(medium) { @extend %clearfix; } } .site-footer { background-color: #757b82; @include bp(medium) { @extend %clearfix; } }
But going the other way?
%some-random-thing { background-color: aliceblue; @media only all and (min-width: 37.5em) { background-color: purple; } @media only all and (min-width: 62.5em) { background-color: tomato; } }
Use the collective power of the Internet to drive your responsive project with Sass.
@include susy-breakpoint(30em, 8) { // nested code uses an 8-column grid, // starting at a 30em min-width breakpoint... .example { @include span(3); } }
http://rp3agency.com (2014)
Coupon Code: WCHRVA
@beep, @bswatson, @codingdesigner, @DCSassMeetup,@kurtroberts, @rwd, @SassCSS, @SassSusy,@snugug, @tropicandid, @WordPressDC, @xiwcx