81
BUILDING BETTER RESPONSIVE SITES Holger Bartel | @foobartel | Harbour Front Monthly #1 on 27/08/2014

Building Better Responsive Websites

Embed Size (px)

DESCRIPTION

Building Better Responsive Sites – This presentation provides tips, tricks and advice for building better responsive websites and how to improve your process and workflows. It also introduces some helpful tools to better name your CSS, improve and automate various other workflows.

Citation preview

Page 1: Building Better Responsive Websites

BUILDING BETTER RESPONSIVE

SITES

Holger Bartel | @foobartel | Harbour Front Monthly #1 on 27/08/2014

Page 2: Building Better Responsive Websites

“RESPONSIVE WEB DESIGN IS ALL ABOUT FLUID GRIDS, FLEXIBLE

IMAGES & MEDIA QUERIES”

Page 3: Building Better Responsive Websites

EASY!http://en.wikipedia.org/wiki/Tightrope_walking

Page 4: Building Better Responsive Websites

http://www.manonwire.com

Page 5: Building Better Responsive Websites

TURNS OUT… NOT QUITE THAT EASY!

Page 6: Building Better Responsive Websites

“It’s Damn Hard!”

– Charis Rooda

Page 7: Building Better Responsive Websites

“And it’s all a big hack!”

– Charis Rooda

Page 8: Building Better Responsive Websites

YOU’LL NEED MORE THAN JUST 3 INGREDIENTS TO COOK A GREAT

MEAL

YOU’LL NEED MORE THAN JUST 3 INGREDIENTS TO COOK A GREAT

MEAL

http://en.wikipedia.org/wiki/pasta

Page 9: Building Better Responsive Websites

★ Fluid Grids, Images & Media Queries

★ Architecture & Structure

★ Performance

Page 10: Building Better Responsive Websites

★ Fluid Grids, Images & Media Queries

★ Architecture & Structure

★ Performance

★ (Maybe a few more things 😉)

Page 11: Building Better Responsive Websites

Talk to your designers, co-workers, project managers (if any) & clients.

!A lot.

COMMUNICATE!

Page 12: Building Better Responsive Websites

GETTING MORE FLEXIBLE WITH FONT SIZE MEASUREMENTS

Page 13: Building Better Responsive Websites

px is an absolute unit of measurement - px units don't scale

!em is not an absolute unit -

it is a unit that is relative to the currently chosen font size.

PIXELS VS. EMS

Page 14: Building Better Responsive Websites

body  {  font-­‐size:62.5%;  }  h1  {  font-­‐size:  2.4em;  }  /*  =24px  */  p    {  font-­‐size:  1.4em;  }  /*  =14px  */  li  {  font-­‐size:  1.4em;  }  /*  =14px?  */  !li  li  {  }  !1.4em  =  14px   BUT  14  *  1.4  =  20

FONT SIZE COMPOUNDS

Page 15: Building Better Responsive Websites

The em unit is relative to the font-size of the parent, which causes the compounding issue.

!The rem unit is relative to the root—or the html—

element.

REM == ROOT EM

Page 16: Building Better Responsive Websites

BUILDING MOBILE FIRST

Page 17: Building Better Responsive Websites

Building from Small Screen Towards Large Screen !

Which in turn saves you from having to overwrite lots of CSS in the long run

BUILDING MOBILE FIRST

Page 18: Building Better Responsive Websites

@media  only  screen  and  (min-­‐width  :  30em)  {  …  }

STARTING LIGHT

Page 19: Building Better Responsive Websites

@media  only  screen  and  (max-­‐width  :  30em)  {  …  }

WHAT ABOUT MAX-WITDH?

Page 20: Building Better Responsive Websites

@media  only  screen    and  (min-­‐width  :  30em)  and  (max-­‐width  :  34.375em)  {  !

  /*  fine  tuning  for  certain  elements  */  !

}

MY EXCEPTIONS

Page 21: Building Better Responsive Websites

ORGANIZING YOUR MEDIA QUERIES

Breakpoints don’t necessarily have to be device sizes !

Rather set them where stuff looks good !

Consider most commonly used devices (Which can be quite a guessing game)

Page 22: Building Better Responsive Websites

You could se"le for fixed breakpoints… but that’s cheating! ✌️

!Why should definitely opt for a fluid grid

FLUID OR FIXED

Page 23: Building Better Responsive Websites

The Mobile Landscape

Page 24: Building Better Responsive Websites

The Many Many Different Flavors

Page 25: Building Better Responsive Websites
Page 26: Building Better Responsive Websites

6 Weeks !

!

!

!

!

!428 Different Devices

=

Page 27: Building Better Responsive Websites
Page 28: Building Better Responsive Websites

http://opensignal.com/reports/2014/android-fragmentation/

Page 29: Building Better Responsive Websites

…and other relative units. !

This way you will be able to provide be!er and more future-proof cross device experiences, even for less

popular devices.

LOVE MORE %

Page 30: Building Better Responsive Websites

Let Your Breakpoints Scale with Font-Size

USING EM’S IN MQ’S

Page 31: Building Better Responsive Websites

@media  only  screen  and  (min-­‐device-­‐width  :  37.5em)  {  …  }

Page 32: Building Better Responsive Websites

100% ZOOM IN 1024PX WIDE VIEWPORT

Page 33: Building Better Responsive Websites

175% ZOOM IN 1024PX WIDE VIEWPORT W/ EM BASED MQ (SAME VIEW AS IN A 320PX VIEWPORT)

Page 34: Building Better Responsive Websites

100% ZOOM IN A 320PX WIDE VIEWPORT

Page 35: Building Better Responsive Websites

<link  rel="stylesheet"  href="css/app.css"  />  <link  rel="stylesheet"  href="css/480.css"  />  <link  rel="stylesheet"  href="css/768.css"  />  <link  rel="stylesheet"  href="css/1024.css"  />  !

OR  @import  “480.css”;  @import  “768.css”;  @import  “1024.css";

THE EARLIER DAYS OF RWD

Page 36: Building Better Responsive Websites

.panel-­‐wrap  {     margin-­‐bottom:  0.5rem;     @include  media(30em)  {       padding-­‐left:  0.3125rem;       padding-­‐right:  0.3125rem;     }     @include  media(38em)  {       padding-­‐left:  0.6375rem;       padding-­‐right:  0.6375rem;     }     @include  media(50em)  {       padding-­‐left:  0.9375rem;       padding-­‐right:  0.9375rem;     }  }

I PREFER ONE FILE WITH INLINE MQ’S

Page 37: Building Better Responsive Websites

_panel.scss

_profile.scss

_cart.scss

_shame.scss

app.scss

IMPORTING PARTIALS

Page 38: Building Better Responsive Websites

SELECTORS & CHOICES

Page 39: Building Better Responsive Websites

CLASSES VS. ID’S

Page 40: Building Better Responsive Websites

1. ID’s & Classes all over the place

2. ID’s for main elements, classes mostly everything else

3. ID’s only for JavaScript, classes for everything CSS

MY SELECTOR EVOLUTION

Page 41: Building Better Responsive Websites

SEMANTIC CLASSES !

VS. !

PRESENTATIONAL CLASSES

Page 42: Building Better Responsive Websites

USE CLASS ATTRIBUTES WITH SEMANTICS IN MIND

Choose your class names to what the element is instead of how it looks

Page 43: Building Better Responsive Websites

.blue-­‐box  {        background:  #51A7F9;      }

Page 44: Building Better Responsive Websites

.blue-­‐box  {        background:  #DC0100;      }

Page 45: Building Better Responsive Websites

.box  {        background:  #F28717;      }

Page 46: Building Better Responsive Websites

ANOTHER ADVANTAGE OF USING SEMANTIC CLASSES OVER PRESENTATIONAL CLASSES

CHANGE ELEMENT APPEARANCE WITHOUT TOUCHING YOUR HTML

Page 47: Building Better Responsive Websites

<div  class=“small-­‐12  medium-­‐8  large-­‐6”>      …  </div>

Page 48: Building Better Responsive Websites

<div  class=“small-­‐12  medium-­‐8  large-­‐6”>      …  </div>

.small-­‐12  {  declaration  here  }  !

.large-­‐6  {  declaration  here  }

Page 49: Building Better Responsive Websites

.news-­‐item-­‐block  {      @extend  .small-­‐12;      @extend  .large-­‐6;  }

<div  class=“news-­‐item-­‐block”>      …  </div>

Page 50: Building Better Responsive Websites

.news-­‐item-­‐block  {      @extend  .to-­‐whatever-­‐you-­‐want;     and-­‐another-­‐property:  value;  }

<div  class=“news-­‐item-­‐block”>      …  </div>

Page 51: Building Better Responsive Websites

CLASS NAMES

Page 52: Building Better Responsive Websites

CLASS NAMING IS HARD

http://en.wikipedia.org/wiki/Macaque#mediaviewer/File:Macaca_nigra_self-portrait.jpg

Page 53: Building Better Responsive Websites

TOOLS & METHODOLOGIES TO SUPPORT BETTER

NAMING & STRUCTURE

Page 54: Building Better Responsive Websites

SMACSS SCALABLE AND MODULAR ARCHITECTURE FOR CSS

https://www.smacss.com

Page 55: Building Better Responsive Websites

http://www.oocss.org

OOCSS OBJECT ORIENTED CSS

Page 56: Building Better Responsive Websites

http://www.bem.info

BEM BLOCK, ELEMENT, MODIFIER

Page 57: Building Better Responsive Websites

DON’T MAKE YOUR LIFE HARDER THAN IT NEEDS TO

BE

Page 58: Building Better Responsive Websites

MY FAVORITE WORD:

SPECIFICITY

Page 59: Building Better Responsive Websites

★ Try to avoid long selector chains

★ They are painful to overwrite

★ Nest 2 or max 3 levels deep

★ Check your output file when nesting rules

Page 60: Building Better Responsive Websites

IF YOU NEED TO USE !IMPORTANT TO OVERWRITE A STYLE, YOU PROBABLY MESSED UP SOMEWHERE ELSE!

Page 61: Building Better Responsive Websites
Page 62: Building Better Responsive Websites

DON’T WORRY ABOUT THE SIZE OF YOUR CSS

!

RATHER CARE ABOUT IMAGE SIZE

Page 63: Building Better Responsive Websites

IMAGES

Page 64: Building Better Responsive Websites

AVERAGE RESPONSIVE SITE SIZE

http://httparchive.org/interesting.php

~ 1.8MB

Page 65: Building Better Responsive Websites

INCREASE SINCE 2011

http://httparchive.org/interesting.php

Page 66: Building Better Responsive Websites

IMAGES OFTEN ACCOUNT FOR MOST OF THE DOWNLOADED

BYTES ON A PAGE. !

OPTIMIZING IMAGES CAN OFTEN YIELD LARGE BYTE

SAVINGS AND PERFORMANCE IMPROVEMENTS.

Page 67: Building Better Responsive Websites

You have to make decisions and sacrifices sometimes. As long as you know why you made them, it should be

alright to do so

MAKE A CALL

Page 68: Building Better Responsive Websites

LARGE OR SMALL

http://en.wikipedia.org/wiki/Tiger

Page 69: Building Better Responsive Websites

RETINA - YES OR NO?

1x 1.5x 2x

Page 70: Building Better Responsive Websites

TOOLS FOR IMAGE OPTIMIZATION

h"p://addyosmani.com/blog/image-optimization-tools/

Page 71: Building Better Responsive Websites

TOOLS & STUFF

Page 72: Building Better Responsive Websites

CODE GUIDE

http://mdo.github.io/code-guide/

Standards for developing flexible, durable, and sustainable HTML and CSS.

Page 73: Building Better Responsive Websites

CHECK HTML5/CSS3 BROWSER FEATURES

http://www.caniuse.com

Page 74: Building Better Responsive Websites

CODEKIT STEROIDS

FOR WEB DEVELOPERS

https://incident57.com/codekit/

Page 75: Building Better Responsive Websites

CROSS-BROWSER TESTING

VirtualBox !

Modern.ie !

Browserstack.com !

Sauce Labs !

Page 76: Building Better Responsive Websites

DEVICE TESTING

Adobe Edge Inspect !

Ghostlab !

BrowserSync! !!!

Page 77: Building Better Responsive Websites

PERFORMANCE TESTING

http://www.webpagetest.org !

http://tools.pingdom.com/fpt/ !

https://developers.google.com/speed/pagespeed/ !

https://developer.yahoo.com/yslow/ !

Page 78: Building Better Responsive Websites

GRUNT JAVASCRIPT TASK

RUNNER

http://www.gruntjs.com

Page 79: Building Better Responsive Websites

GULP ANOTHER TASK

RUNNER

http://www.gulpjs.com

Page 80: Building Better Responsive Websites

“RESPONSIVE WEB DESIGN ISN’T QUITE ONLY ABOUT FLUID

GRIDS, FLEXIBLE IMAGES & MEDIA QUERIES”

Page 81: Building Better Responsive Websites

THANKS!

Holger Bartel | @foobartel | Harbour Front Monthly #1 on 27/08/2014