This document discusses how Sass can simplify responsive design. It provides examples of using Sass mixins to generate different CSS for different screen sizes from a single codebase. Key points:
- Sass mixins like @include mobile and @include desktop allow generating CSS rules that only apply at certain screen sizes.
- Setting a $responsive variable controls whether responsive or fixed-width CSS is output. This allows two builds from one codebase.
- Combining SMACSS and Sass mixins allows semantic layout classes that adapt different sub-layouts at breakpoints.
- Lessons included unexpected browser issues, simplifying class-based approaches, and making markup responsive-ready.
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
How Sass Can Simplify Responsive Design
1. How Sass Can Simplify
Responsive Design
The Mixin · June 28, 2013
Alan Hogan
2. Topics
Experiences taking a major website responsive
Simple, powerful Sass patterns
Lessons learned
Combining Sass and SMACSS in a responsive context
18. More Surprises
IE9 cannot size SVG responsively
(width: 100%; height: auto only works on rasters)
IE9 lack of support for input placeholder="..."
led to bugs
19. Failed Approach: Based off class names
.responsive {
@media { ... }
}
.fixed-width {
// ...
Unwanted extra specificity
}
and
IE8 temper tantrums
20. Doing Markup Right
Server-side abstraction + responsive JS lib = easy
<div data-responsive-content=
'{"desktop":"Desktop!"}'>
Mobile first!
</div>
27. .layout-icon-grid {
// A layout that works at all brkpts
}
.mobile-layout-linear {
// Designed only for, and applies
// only for, mobile screen sizes
@include mobile { ... }
}
.desktop-layout-columns {
// No effect on mobile
@include desktop { ... }
}