Responsive Webdesign –
as easy as it sounds
TYPO3 Conference 2014
Sven Wolfermann | maddesigns
TYPO3 Conference 2014
Sven Wolfermann | maddesigns
2010 “We need a mobile site!”
2012 “Let's make it responsive!”
2014 “Holy crap!”
solves many things
*, *:before, *:after { box-sizing: border-box; }
understand the viewport
<meta name="viewport" content="width=device-width,initial-scale=1.0">
Android Chrome vs iOS7
Code-Example:
if ( touch ) {
/* make touch friendly */
} else {
/* oh just kidding, keep
everything touch friendly */
}
Responsive Content manifest:
the smaller the device , the more important is it to put important content at the beginning of the page
Google honored RWD, and shows an icon for mobile optimized websites in SERPs now
Nowadays we don't know how and where the user visits our website
do you remember 2 years ago?
Slides: Responsive Workflow
Simple Grids: 50%, 33%, 25%, …
many Gridsystems…
http://codepen.io/maddesigns/full/EBlHd/
http://codepen.io/maddesigns/full/yJdiL/
Blog-Post (german)
It’s easy to make a bunch of boxes responsive
http://codepen.io/maddesigns/pen/LeqEu
Fallback: http://codepen.io/maddesigns/pen/sAjgo
http://codepen.io/maddesigns/pen/pHqnt
Blog-Post (german)
For third party widgets, sometimes you just have to to do…
table[width=“575px”] {
width: 100%;
}
http://codepen.io/jordanmoore/details/pnlAi/
Client: , Project: DHBW CAS, in Cooperation with: Spooner Web
Translation: if you have to develop a multi level responsive navigation, estimate the effort by level. 2 level = twice effort, 4 levels = 4x
html {
-webkit-text-size-adjust: 100%;
-ms-text-size-adjust: 100%;
}
input, select, textarea {
font-size: 16px; /* (1em) */
}
more about responsive typography (german)
body { font-size: 1em; }
@media only screen and (min-width: 600px) { body { font-size: 1.5em; } }
@media only screen and (min-width: 750px) { body { font-size: 2em; } }
@media only screen and (min-width: 1000px) { body { font-size: 2.5em; } }
rem font size based on root element (<html>)
span { font-size: 1rem; /* 16px / 16px */ }
Attention! rem based on <html>
=> default mostly 100% => 16px!
html { font-size: 100%; } /* 16px */ body { font-size: 1em; } /* 16px */
Set font-size to 16px to be sure that rem base value is 16px. Some browsers have higher default values.
$base-fontsize: 16px;
@function rem($target, $context: $base-fontsize) {
@if $old-ie == true {
@return strip-units($target) * 1px;
}
@else {
@return (strip-units($target) / strip-units($context)) * 1rem;
}
}
Usage:
h1 {
font-size: rem(24px);
}
CSS:
h1 {
font-size: 1.5rem;
}
CSS (IE8-Fallback):
h1 {
font-size: 24px;
}
more advanced Sass rem mixin
https://gist.github.com/maddesigns/6415889
1vw = 1% of viewport width 1vh = 1% of viewport height 1vmin = 1vw or 1vh, whichever is smaller 1vmax = 1vw or 1vh, whichever is larger
Usage:
h1 { font-size: 5.9vw; } h2 { font-size: 3.0vh; } p { font-size: 2vmin; }
Web fonts in modern browser
Blog Post: „Webfonts how to” (german)
for Typekit, Google, Fontdeck, Fonts.com, … and self hosted fonts
<script> WebFontConfig = { typekit: { id: 'xxxxxx' } }; (function() { var wf = document.createElement('script'); wf.src = ('https:' == document.location.protocol ? 'https' : 'http') + '://ajax.googleapis.com/ajax/libs/webfont/1.4.7/webfont.js'; wf.type = 'text/javascript'; wf.async = 'true'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(wf, s); })(); </script>
CSS selectors for font events
.wf-loading .wf-active .wf-inactive .wf-<familyname>-<fvd>-loading .wf-<familyname>-<fvd>-active .wf-<familyname>-<fvd>-inactive
h1, h2, h3 { font-family: sans-serif; } .wf-active h1, .wf-active h2, .wf-active h3 { font-family: "webfont", sans-serif; }
Font Awesome is a full suite of 479 pictographic icons
If you only use a bunch of icons, strip down the files with icomoon.io
pick your icons
save as font (or SVG)
save Kb!
Blog post: SVG Sprites vs. Icon Fonts (german)
great for logos & Icons
<img src="img/SVG-logo.svg" width="100" alt="">
<img src="img/SVG-logo.svg" width="200" alt="">
<img src="img/SVG-logo.svg" width="300" alt="">
my blog post (german)
<svg version="1.0" …>
<defs>
<style type="text/css"><![CDATA[
@media screen and (max-width: 280px) {
.logo-subline {
display: none;
}
}
@media print {
.logo .logo-item1 {
fill: #000;
}
.logo .logo-item2 {
fill: #FFF;
stroke: #000;
stroke-width: 2pt;
}
}
]]></style>
</defs>
<g class="logo"> …
After 3 years we have a standardized solution
<picture> & srcset + sizes
<img
srcset=" large.jpg 1200w,
medium.jpg 600w,
small.jpg 360w"
sizes=" (min-width: 50em) 33vw,
(min-width: 28em) 50vw,
100vw"
src="small.jpg"
alt="alttext"
/>
native support for picture/srcset: Chrome 38, Firefox 33, Safari 8, ...)
first step
img,iframe {
max-width: 100%;
}
second step – fluid container
<div class="embed-container">
<iframe
width="640"
height="360"
src="https://www.youtube-nocookie.com/embed/9T7eSyo7DRU"
frameborder="0"
allowfullscreen>
</iframe>
</div>
.container {
max-width: 800px;
}
.responsive-embed {
position: relative;
padding-bottom: 56.25%; /* ratio16x9 */
padding-top: 30px; /* youtube specific */
height: 0;
width: 100%;
overflow: hidden;
> iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
}
ok, ok, Oakley does it better now:
JUST 14.2MB, 291 request (more than 70MB less)
with mobile user-agent? 6.7MB, 114 requests :/
has some issues
sites have nearly same weight on mobile as on desktop
include one Facebook Like Button and one Youtube iframe
1Mb fonly for Facebook and Youtube JS
Sven Wolfermann | @maddesigns | maddesigns.de