responsive design tools & resources

188
Responsive Design in the Real World Tools & Resources to Make Responsive Design Easier Cleveland Web Standards Association October 30, 2012 Clarissa Peterson @clarissa

Upload: clarissa-peterson

Post on 27-Jan-2015

103 views

Category:

Design


0 download

DESCRIPTION

Covers frameworks, navigation patterns, preprocessors, responsive images, responsive data tables, polyfills. Presentation at the Cleveland Web Standards Association, October 30, 2012.

TRANSCRIPT

Page 1: Responsive Design Tools & Resources

Responsive Designin the Real WorldTools & Resources to MakeResponsive Design Easier

Cleveland Web Standards AssociationOctober 30, 2012

Clarissa Peterson@clarissa

Page 2: Responsive Design Tools & Resources

What We’ll Cover:Frameworks

Navigation Patterns

Preprocessors

Responsive Images

Responsive Data Tables

Polyfills

Page 3: Responsive Design Tools & Resources

Captions added for those of you playing along at home!

Almost as good as being there.*

Page 4: Responsive Design Tools & Resources

Responsive Web Design

This is not an introduction to responsive web design. If you’ve been doing some responsive design, or at least know what it is pretty well, this presentation is going to tell you about some tools and resources that will make it easier for you to build

responsive sites. But for those of you who need a little background, I’m going to explain reaaaaally quickly what responsive design is. The rest of you can just click

forward a few slides. The non-technical description first:

Page 5: Responsive Design Tools & Resources

When the iPhone was introduced, this is what websites looked like. They were very, very tiny, and you had to zoom in and out to read anything.

Page 6: Responsive Design Tools & Resources

This kind of sucked, because if you made the text big enough to read, you couldn’t even see the whole line of text at once. (yes, a lot of sites are still like this)

Page 7: Responsive Design Tools & Resources

Responsive Web Design

Responsive design solves that problem. Instead of making the website really tiny so it fits, the browser is able to keep the content a normal size regardless of what size your screen is, and then it just kind of rearranges everything so it fits on the screen in a way that

makes sense and takes advantage of the available space.

Page 8: Responsive Design Tools & Resources

Go to the Boston Globe site in your browser and then make the browser window narrower and wider — see what happens. The text stays the same size, but the content rearranges from three columns to two and then one column as the browser window gets narrower. That’s responsive design.

http://www.bostonglobe.com

Page 9: Responsive Design Tools & Resources

Resizing your browser window is just an easy way to see the changes all at once. But what we’re really talking about is the difference in how a site looks from one device to the next — such as a mobile phone, a tablet, a

laptop, or a desktop computer. Making your browser window very narrow (about 300 pixels) will give you a decent idea of what a website looks like on a mobile phone, but not entirely. Make sure to test on actual devices.

Page 10: Responsive Design Tools & Resources

1. Flexible Grid2. Flexible Images/Media

3. Media Queries

There are three parts to responsive design.

Page 11: Responsive Design Tools & Resources

1. Flexible Grid2. Flexible Images/Media

3. Media Queries

The first two, the flexible grid and flexible images/media are pretty easy to explain.

Page 12: Responsive Design Tools & Resources

I’ll demonstrate on The Boston Globe site. This is the site at about 1280 pixels wide.

http://bostonglobe.com/

Page 13: Responsive Design Tools & Resources

This is the site at a somewhat narrower width. Note that the columns have each decreased in width in proportion to the site. So has that big picture off on the left. That’s because everything is measured in percent instead of pixels.

http://bostonglobe.com/

Page 14: Responsive Design Tools & Resources

In contrast, check out the Milwaukee Journal-Sentinel website. It’s also a newspaper, also with three columns.

http://www.jsonline.com/

Page 15: Responsive Design Tools & Resources

But look what happens at a narrower width. The columns all stayed the exact same width, so although the empty margins gave us some room to maneuver, after those were gone, the browser had no choice but to chop off the right side of the page.

http://www.jsonline.com/

Page 16: Responsive Design Tools & Resources

1. Flexible Grid2. Flexible Images/Media

3. Media QueriesThe third part of responsive design is media queries. This is the magic part of responsive design. Okay, it’s not really magic. It’s actually pretty simple how a

media query works. It’s just an if-then statement, if any of you are programmers. And even if you’re not a programmer, the concept is simple:

Page 17: Responsive Design Tools & Resources

That’s a media query. In responsive design, what we’re generally going to be querying is the viewport width. That is more or less the same thing as the

width of your browser, which is why we can resize our browser window to demonstrate responsive design. For mobile devices, the viewport width is essentially the same thing as the screen width, since you can’t have a non-full-size browser window like you can on your computer. So you’ll often

hear people referring to screen width in responsive design when they really mean viewport width. They know what they mean, though.

If X is true, then do Y. If X is not true, then don’t do Y.

If those letters look too much like algebra, I can give you an example: If the time is 12:00, eat lunch. If the time is not 12:00, then don’t eat

lunch. That sounds pretty straightforward, right?

Page 18: Responsive Design Tools & Resources

In responsive design, media queries are querying the viewport width, and telling the browser to do something different depending on the viewport width.

http://www.unitedpixelworkers.com/

Page 19: Responsive Design Tools & Resources

So as the viewport gets wider on the United Pixelworkers site, you can see the site looks different. The icons at the top rearranged themselves a bit, and the font changed size.

http://www.unitedpixelworkers.com/

Page 20: Responsive Design Tools & Resources

Now, there are two columns instead of one! The media query is telling the browser: When the viewport is wider than X pixels, do this section of the CSS to make it be two columns instead of one. If the viewport is not wider, ignore that

http://www.unitedpixelworkers.com/

Page 21: Responsive Design Tools & Resources

And things just keep on rearranging! You can have as many media queries as you want.

http://www.unitedpixelworkers.com/

Page 22: Responsive Design Tools & Resources

And a media query can make pretty much any change to the CSS that is being used to render the website. For responsive design,

normally it’s going to be parts of the CSS having to do with layout.http://www.unitedpixelworkers.com/

Page 23: Responsive Design Tools & Resources

But if you wanted, you could make the entire site turn purple if the screen is wider than X pixels. I’m not sure why you’d want to do that, but you could.

http://www.unitedpixelworkers.com/

Page 24: Responsive Design Tools & Resources

@media screen and (min-width: 640px) { .section1, .section2 { float: left; width: 50%; }}

This is what a media query looks like.

Page 25: Responsive Design Tools & Resources

@media screen and (min-width: 640px) { .section1, .section2 { float: left; width: 50%; }}

This is the “if” part of the if-then statement. All media queries start with @media. Then we’re saying: if you’re displaying this page on a screen (as opposed to print or something else), AND the viewport is a minimum of 640 pixels wide...

Page 26: Responsive Design Tools & Resources

@media screen and (min-width: 640px) { .section1, .section2 { float: left; width: 50%; }}

This part in the middle is the “then.” If the query is true, then do this CSS. If the query is not true, then ignore this CSS. It is THAT easy!

Page 27: Responsive Design Tools & Resources

@media screen and (min-width: 40em) { .section1, .section2 { float: left; width: 50%; }}

You’ll notice our query was for a viewport width of 640 pixels or wider. Actually, a better way to do a media query is to use ems instead of

pixels, so the page will be even more flexible. Ems relate to the base font size for the page. So if our page has a different-than-usual base font size, either via the browser or via user preferences, things will still look okay.

Page 28: Responsive Design Tools & Resources

Tools & Resources

Page 29: Responsive Design Tools & Resources

You’ve probably heard that responsive design is hard. Well, it isn’t. I mean, it’s not any harder than web design is. Sure, web design was a lot easier in the days before computers were invented. We just sat around

and read the paper all day, waiting for computers to be invented.

Page 30: Responsive Design Tools & Resources

And it turns out that the awesome thing about web design is that there are a lot of people out there who want us to copy their stuff. In fact, they make cool stuff

and put it on their websites for everybody to download and use. Our job as responsive designers is actually not all that hard, because there are people out

there who are much smarter than us, and they are doing all the hard parts for us!

Sure, it’s nice to be a purist and code all our websites from scratch. Just like we make all our own clothes from fabric that we wove ourselves from cotton that

we grew ourselves on our own farms in our backyard. Right?

Or we can let someone else do the hard parts so that we can gohome at a reasonable hour in time to play with our kids

or watch Law & Order: SVU (your choice).

But eventually we had to learn HTML and CSS. We didn’t try to learn it all at once, so it wasn’t too bad. Plus, we just

copied other people’s stuff until we got the hang of it.

Page 31: Responsive Design Tools & Resources

Frameworks

A framework is a starting place for designing or building a website. Not the whole design, just a starting place. Like the frame of a house.

Page 32: Responsive Design Tools & Resources

There are a lot of frameworks, and they’re all a bit different, so you’ll have to figure out what works best for your project and for your style of working. Foundation is

one of the most popular. It’s a 12-column, nestable, responsive grid. http://foundation.zurb.com/

Page 33: Responsive Design Tools & Resources

That doesn’t mean your site will have 12 columns. You can have any number of columns up to 12, as long as the proportions are divisible by 12. For example, you can have two columns, the first is 4/12 of the screen wide, the other is 8/12 wide.

http://foundation.zurb.com/grid-example1.php

Page 34: Responsive Design Tools & Resources

http://www.zurb.com/soapbox

Here’s a site that uses Foundation.

Page 35: Responsive Design Tools & Resources

Once you decide what columns you want, that doesn’t have to apply to the whole page. Here they have 4 columns, (3+3+3+3) and right below that, 3 columns (4+4+4).

http://www.zurb.com/soapbox

Page 36: Responsive Design Tools & Resources

When you download all the files for Foundation, you get CSS, JavaScript, and this sample file which you can use as a template (or you

can just start your own HTML page and not use the template).http://foundation.zurb.com/

Page 37: Responsive Design Tools & Resources

http://foundation.zurb.com/

It’s responsive by default.

Page 38: Responsive Design Tools & Resources

There’s only one breakpoint, and the default behavior is for the columns to stack vertically. This might not be what you want to happen, but you can change it to

work however you want by adding more breakpoints or different behavior.http://foundation.zurb.com/

Page 39: Responsive Design Tools & Resources

<div class="row">

<div class="twelve columns">

...

</div>

</div>

<div class="row">

<div class="three columns">

...

</div>

<div class="nine columns">

...

</div>

</div>

The grid is built around two key elements: rows and columns. Each row gets a class of “row.”

Page 40: Responsive Design Tools & Resources

<div class="row">

<div class="twelve columns">

...

</div>

</div>

<div class="row">

<div class="three columns">

...

</div>

<div class="nine columns">

...

</div>

</div>

The columns within the rows: each gets a class of “columns,” and then a number that correlates as to how wide it should be out of 12. The first row

has one column that spans the entire width of 12. The next row has a narrow left column (3 of 12) and a wider right column (9 of 12).

Page 41: Responsive Design Tools & Resources

Responsive

Foundation is by default responsive. All the widths are percentages. It has one breakpoint at 768 pixels, but you’re not

stuck with that; you can easily change it or add more breakpoints.

Page 42: Responsive Design Tools & Resources

class="show-for-xlarge"class="show-for-large"class="show-for-large-up"class="show-for-medium"class="show-for-medium-down"class="show-for-small"

breakpoints at:767 px, 1279 px, 1441 px

There are built-in classes you can use to show or hide elements at specific widths; for example, if you want a nav button to appear on small screens, but the full nav to

appear on wide screens. You can change the built-in breakpoints.

Page 43: Responsive Design Tools & Resources

class="hide-for-xlarge"class="hide-for-large"class="hide-for-large-up"class="hide-for-medium"class="hide-for-medium-down"class="hide-for-small"

breakpoints at:767 px, 1279 px, 1441 px

Page 44: Responsive Design Tools & Resources

class="show-for-landscape"class="hide-for-landscape"

class="show-for-portrait"class="hide-for-portrait"

class="show-for-touch"class="hide-for-touch"

You probably won’t use these much, but there are built-in classes to show/hide elements depending on screen orientation, or whether it’s a touch screen.

Page 45: Responsive Design Tools & Resources

Prototyping

You already know that prototyping/designing in PhotoShop doesn’t work when you need to plan for varying screen widths. Frameworks are really great for

responsive prototyping, because you can build a basic site layout very quickly.

Page 46: Responsive Design Tools & Resources

http://foundation.zurb.com/docs/forms.php

Frameworks generally come with built-in styles for various elements, such as forms and buttons. You probably won’t use these basic, default styles on

your actual design, but they are handy when doing a quick prototype.

Page 47: Responsive Design Tools & Resources

http://foundation.zurb.com/docs/buttons.php

And they are basic enough that the site will look like a prototype and not a finished design, so your client won’t be confused.

Page 48: Responsive Design Tools & Resources

http://foundation.zurb.com/docs/typography.php

Typography styles are also included.

Page 49: Responsive Design Tools & Resources

http://twitter.github.com/bootstrap/index.html

Twitter Bootstrap is another framework that is very popular. Besides giving you a responsive grid, there are also lots of pre-styled UI elements.

Page 50: Responsive Design Tools & Resources

http://www.getskeleton.com

Skeleton is another responsive framework. It’s more lightweight (less styled elements), easy to use, and there are WordPress and Drupal versions.

Page 51: Responsive Design Tools & Resources

320 and Up is a great framework, because it’s intended for small-screen first. That’s the best way to design a responsive site: by starting with the small screen, you can focus on your content, which is the most important part of your site.

http://stuffandnonsense.co.uk/projects/320andup/

Page 52: Responsive Design Tools & Resources

http://simplegrid.info/

SimpleGrid is another responsive framework. It has three different breakpoints by default. Again, you can make any changes you want. It’s very simple to implement.

Page 53: Responsive Design Tools & Resources

http://semantic.gs/

The Semantic Grid System is a little more complicated, but allows you to set variables for things like gutter and column widths.

Page 54: Responsive Design Tools & Resources

Frameless is not exactly a framework — you don’t download anything — but more of a way to code your site.

http://framelessgrid.com/

Page 55: Responsive Design Tools & Resources

http://html5boilerplate.com/

HTML5 Boilerplate is HTML5 by default, and includes a lot of additional styles, tools, and polyfills to help you build your site.

Page 56: Responsive Design Tools & Resources

http://goldengridsystem.com/

The Golden Grid System is a “folding grid”: the columns collapse from 16 to 8 to 4 as the viewport narrows.

Page 58: Responsive Design Tools & Resources

Navigation Patterns

One of the tricky parts about making a responsive site is figuring out what to do with the navigation. The good news

is that someone else already figured it out for us.

Page 59: Responsive Design Tools & Resources

http://bradfrost.github.com/this-is-responsive/patterns.html

Brad Frost has this great website where you can view sample code for different types of things you might want to add to your

responsive site. (there are a lot of other links and resources too)

Page 60: Responsive Design Tools & Resources

Top Navigation

Navigation nearly always follows one of several “patterns.” The first we’ll look at is top navigation. This is the easiest thing to do with your

navigation, and generally requires only minimal CSS to make it responsive.

Page 61: Responsive Design Tools & Resources

When we go from wide to narrow width (on the next slide), you’ll see that the navigation stays in the same part of the page. It moves

down below the logo, but otherwise is pretty much the same.http://www.gravitatedesign.com

Page 62: Responsive Design Tools & Resources

This may work okay if we only have a few navigation items, but they might end up wrapping in weird ways. Or we may have to make them really small so they’ll fit, in

which case it would be difficult to accurately select the links on a touch screen.http://www.gravitatedesign.com

Page 63: Responsive Design Tools & Resources

http://www.tuj.ac.jp/

This site has a lot of different navigations and navigation items. They used a strategy of keeping all the nav items at the top...

Page 64: Responsive Design Tools & Resources

But what happens is they end up filling the whole screen with navigation, and you can’t see the content. People aren’t coming to our websites for

the navigation, they’re coming for the content. So this isn’t good.http://www.tuj.ac.jp/

Page 65: Responsive Design Tools & Resources

Footer Anchor

Footer anchor navigation is also fairly simple to implement. (by the way, all the code examples in this section are from Brad Frost’s This Is Responsive site)

Page 66: Responsive Design Tools & Resources

This is Contents magazine. This is what the site looks like on a desktop. Basic horizontal navigation.

http://contentsmagazine.com/

Page 67: Responsive Design Tools & Resources

On a small screen, instead of seeing navigation at the top, you see a button, “Explore.” You click this to get to the navigation. It’s an anchor link.

http://contentsmagazine.com/

Page 68: Responsive Design Tools & Resources

When you click it, you jump down to the bottom of the page where the navigation is. The problem with this is that it can be disorienting to the user to jump around

on the page. However, it’s really easy to implement footer anchor navigation.

http://contentsmagazine.com/

Page 69: Responsive Design Tools & Resources

<div id="site-nav">

<form> ... </form>

! <nav>

! ! <ul class="nav nav-primary">

! ! ! <li><a href="#">Archive</a></li>

! ! ! <li><a href="#">About</a></li>

! ! ! <li><a href="#">Write For Us</a></li>

! ! ! <li><a href="#">Subscribe</a></li>! ! !

! ! </ul>

! </nav>

</div>

The way this works is that the navigation is at the end of the HTML source order, so by default it’s at the bottom of the screen. So that’s what you get

on the small screen, with the “Explore” button at the top of the page.

Page 70: Responsive Design Tools & Resources

@media screen and (min-width: 48em) {! #site-nav {! ! position: absolute;! ! top: -5em;! ! width: 100%;! ! z-index: 5;! }}

For larger screens, there’s a media query. This simply takes the div containing the navigation, and uses absolute positioning to put it at the top

of the page. That only happens when the viewport is 48 ems or wider.

Page 71: Responsive Design Tools & Resources

So here it is at the top. That was just the positioning; you’ll need some additional CSS to make it look the way you want.

http://contentsmagazine.com/

Page 72: Responsive Design Tools & Resources

Toggle Navigation

Toggle navigation is a bit more complicated to implement. You’ll see a full navigation at a wide screen width. At narrow width, you’ll get a Menu button or icon at the top, which you’ll click to see the navigation. This is getting to be pretty common.

Page 73: Responsive Design Tools & Resources

http://starbucks.com/

This is the Starbucks site. The three-line icon in the top right means navigation. It’s a fairly common convention.

Page 74: Responsive Design Tools & Resources

http://starbucks.com/

When you click it, you get the navigation, and the rest of the page content is pushed down below it (the navigation doesn’t overlap the content).

Page 75: Responsive Design Tools & Resources

http://starbucks.com/

The site has media queries to put the nav items either in one or two columns, depending on how much width is available. When you click the ‘X,’

the navigation will disappear and the content will go back to it’s normal spot.

Page 76: Responsive Design Tools & Resources

http://bradfrost.github.com/this-is-responsive/patterns.html

Starbucks uses a toggle navigation, which is one of the patterns on Brad Frost’s website, so you can look at this example code to see exactly

how it works, and then implement a toggle navigation on your own site.

Page 77: Responsive Design Tools & Resources

http://bradfrost.github.com/this-is-responsive/patterns.html

The example works the same as Starbucks’ site, but has minimal styling so it’s easier for you to see which parts of the code are relevant.

Page 78: Responsive Design Tools & Resources

<a href="#menu" class="menu-link">Menu</a><nav class="" id="menu" role="navigation">! <ul>! ! <li><a href="#">Home</a></li>! ! <li><a href="#">About</a></li>! ! <li><a href="#">Products</a></li>! ! <li><a href="#">Services</a></li>! ! <li><a href="#">Contact</a></li>! </ul></nav>

This is the HTML. The line at the top is the Menu button.

Page 79: Responsive Design Tools & Resources

<a href="#menu" class="menu-link">Menu</a><nav class="" id="menu" role="navigation">! <ul>! ! <li><a href="#">Home</a></li>! ! <li><a href="#">About</a></li>! ! <li><a href="#">Products</a></li>! ! <li><a href="#">Services</a></li>! ! <li><a href="#">Contact</a></li>! </ul></nav>

Below that is the navigation, an unordered list inside a <nav> element.

Page 80: Responsive Design Tools & Resources

.js nav[role=navigation] { ! overflow: hidden;! max-height: 0;}nav[role=navigation].active { ! max-height: 15em;}

This is the CSS to make the navigation appear and disappear.

Page 81: Responsive Design Tools & Resources

.js nav[role=navigation] { ! overflow: hidden;! max-height: 0;}nav[role=navigation].active { ! max-height: 15em;}

There are two relevant lines of CSS that apply to the <nav>: one shows the navigation, the other hides it. We’ll switch between the CSS using JavaScript, which will apply the class “active” to the <nav> element when the Menu button is clicked.

Page 82: Responsive Design Tools & Resources

.js nav[role=navigation] { ! overflow: hidden;! max-height: 0;}nav[role=navigation].active { ! max-height: 15em;}

The first line of CSS, before the Menu button is clicked, hides the <nav>. So the navigation is already hidden when the page loads for the first time.

Page 83: Responsive Design Tools & Resources

.js nav[role=navigation] { ! overflow: hidden;! max-height: 0;}nav[role=navigation].active { ! max-height: 15em;}

The second line of CSS makes the <nav> visible by giving it a max-height of 15em (so it’s no longer hidden, and there’s plenty of space to display the whole thing).

Page 84: Responsive Design Tools & Resources

<script>

(function() {

$(document).ready(function() {

$('body').addClass('js');

var $menu = $('#menu'),

$menulink = $('.menu-link');

$menulink.click(function() {

$menulink.toggleClass('active');

$menu.toggleClass('active');

return false;

});});

})();

</script>

This is the JavaScript. It uses toggleClass from jQuery to add and remove the “active” class to the <nav>.

Page 85: Responsive Design Tools & Resources

@media screen and (min-width: 48.25em) {! a.menu-link {! ! display: none;! }! .js nav[role=navigation] {! ! max-height: none;! }}

For the wide screen, of 48.25em or wider, we’re using this media query to override what we just set up for the narrow screen.

Page 86: Responsive Design Tools & Resources

@media screen and (min-width: 48.25em) {! a.menu-link {! ! display: none;! }! .js nav[role=navigation] {! ! max-height: none;! }}

The first line of CSS hides the Menu button, because we don’t need it on the wide screen: the navigation is visible.

Page 87: Responsive Design Tools & Resources

@media screen and (min-width: 48.25em) {! a.menu-link {! ! display: none;! }! .js nav[role=navigation] {! ! max-height: none;! }}

The second line gives the <nav> the max-height of none. This isn’t the same as zero; it actually means unlimited. There is no maximum. The

<nav> can take all the space it needs on the wide screen.

Page 88: Responsive Design Tools & Resources

To determine where to put your breakpoint for this type of navigation, you just have to try it out and see where the horizontal navigation starts to wrap. Keep in

mind it might be slightly different on different devices or browsers.

Page 89: Responsive Design Tools & Resources

Left Nav Flyout

Left nav flyout is also used a lot, but it’s more complicated to implement, so I’m not going to show you the code, but I’ll show you what it looks like.

Keep in mind that as the navigation code gets more complicated, you need to make sure there’s a fallback for any devices/browsers that don’t support the code. You

don’t want users coming to your site and not having access to the navigation.

Page 90: Responsive Design Tools & Resources

Like the previous example, there’s an icon at the top, horizontal bars, to click to get the navigation.

http://www.emerilsrestaurants.com

Page 91: Responsive Design Tools & Resources

The difference is that here, the content slides off to the side, instead of sliding down. You would then click the navigation icon again to go back to the content.

Notice how you can still see the content, so you know that it’s still there.http://www.emerilsrestaurants.com

Page 92: Responsive Design Tools & Resources

You can also have submenus within the navigation.

http://www.emerilsrestaurants.com

Page 93: Responsive Design Tools & Resources

Three-Dimensional Menu

This isn’t from the navigation patterns that I referred to, but it’s an example of something pretty cool.

Page 94: Responsive Design Tools & Resources

See the arrow over on the left side of the screen? To get the navigation to appear, you just swipe on your touch screen. On a non-touch interface, you

simply need to hover your cursor on the left side of the browser.http://lab.hakim.se/meny/

Page 95: Responsive Design Tools & Resources

After you swipe/hover, you get this. It’s similar to the previous example of left nav flyout, but instead of the content just moving to the right, it is

displayed so that it looks like a side of a cube that has turned.http://lab.hakim.se/meny/

Page 96: Responsive Design Tools & Resources

This is how it looks on a mobile device.

http://lab.hakim.se/meny/

Page 97: Responsive Design Tools & Resources

Resources: Navigation

Responsive Navigation Patterns (Brad Frost) - February 2012http://bradfrostweb.com/blog/web/responsive-nav-patterns/

Complex Navigation Patterns for Responsive Design (Brad Frost) - August 2012http://bradfrostweb.com/blog/web/complex-navigation-patterns-for-responsive-design/

10 Tips How To Handle Responsive Navigation Menus Successfully (Sabina Idler) - October 2012http://blog.usabilla.com/10-tips-how-to-handle-responsive-navigation-menus-successfully/

10 Responsive Navigation Solutions and Tutorials - August 2012http://speckyboy.com/2012/08/29/10-responsive-navigation-solutions-and-tutorials/

Page 98: Responsive Design Tools & Resources

Preprocessors

Next, lets talk about how we write CSS. A preprocessor helps you write CSS. It doesn’t add new functionality to the CSS, but rather it makes your CSS more flexible and easier to maintain.

Page 99: Responsive Design Tools & Resources

There are several different preprocessors. Sass and LESS are two of the more popular. They all do similar things, but have some different features and work in

different ways. You need to pick which one works best for you.http://sass-lang.com/ and http://lesscss.org/

Page 100: Responsive Design Tools & Resources

Sass

I’m not going to say that one or another is better, but for the purpsoes of this presentation, I need to pick one for the examples, so I’m going to show you a bit of

how Sass works. (all code examples are from the Sass website)

Page 101: Responsive Design Tools & Resources

The easiest way to explain how this works: you’ll still be writing CSS for your site, but in special files that have a different extension. You then have

the ability to add in what are essentially shortcuts as part of your CSS.

The preprocessor then will take the files with all your shortcuts and change them to regular CSS files. When the website is rendered, the browser will be looking at the regular CSS files, not your shortcuts.

It’s called a preprocessor because your code will be processed to change it to valid CSS before it’s processed by the browser to render the website.

Page 102: Responsive Design Tools & Resources

Nesting

Nesting is really handy to keep you from repeating the same things over and over again in your CSS, and also can make it easier to

understand your CSS when you’re looking at a lot of it.

Page 103: Responsive Design Tools & Resources

#navbar { width: 80%; height: 23px; ul { list-style-type: none; } li { float: left; }}

Here we are nesting the ul and li within the #navbar.

Page 104: Responsive Design Tools & Resources

#navbar { width: 80%; height: 23px; ul { list-style-type: none; } li { float: left; }}

All the other CSS is contained within #navbar

Page 105: Responsive Design Tools & Resources

#navbar { width: 80%; height: 23px; ul { list-style-type: none; } li { float: left; }}

The width and height only apply to #navbar

Page 106: Responsive Design Tools & Resources

#navbar { width: 80%; height: 23px; ul { list-style-type: none; } li { float: left; }}

But then we have the ul and li within #navbar. So they’re actually #navbar ul and #navbar li.

Page 107: Responsive Design Tools & Resources

#navbar { width: 80%; height: 23px; }#navbar ul { list-style-type: none; }#navbar li { float: left; }

When the code is processed, we get this, which is no longer nested, and is what the browser will get. It doesn’t seem all that impressive in this example, but once you

have multiple layers of nesting, it can make your job a lot easier.

Page 108: Responsive Design Tools & Resources

.fakeshadow {

border: {

style: solid;

left: {

width: 4px;

color: #888;

}

right: {

width: 2px;

color: #ccc;

}

}

}

You can also nest styles.

Page 109: Responsive Design Tools & Resources

.fakeshadow { border-style: solid; border-left-width: 4px; border-left-color: #888; border-right-width: 2px; border-right-color: #ccc; }

This is what the preceding code will turn into when it’s processed.

Page 110: Responsive Design Tools & Resources

Variables

Variables are super-handy. If you have something like a color that is repeated throughout your styles, you can declare it once and then refer to the variable. If you need to change it later, there is only one place to change it instead of many.

Page 111: Responsive Design Tools & Resources

$main-color: #ce4dd6;$style: solid;

#navbar { border-bottom: { color: $main-color; style: $style; }}

Variables start with a dollar sign and are declared like properties.

Page 112: Responsive Design Tools & Resources

$main-color: #ce4dd6;$style: solid;

#navbar { border-bottom: { color: $main-color; style: $style; }}

So then our styles can simply refer to the variable.

Page 113: Responsive Design Tools & Resources

#navbar { border-bottom-color: #ce4dd6; border-bottom-style: solid; }

When it’s processed, we get this.

Page 114: Responsive Design Tools & Resources

Mixins

Mixins are awesome. They allow you to reuse complicated styles without having to copy and paste. Kind of like variables, except for entire styles.

Page 115: Responsive Design Tools & Resources

#navbar li { -moz-border-radius-top: 10px; -webkit-border-top-radius: 10px; border-top-radius: 10px;}

#footer { -moz-border-radius-top: 10px; -webkit-border-top-radius: 10px; border-top-radius: 10px;}For example, if we were using this border radius for multiple elements on the site. We don’t want to copy and paste it multiple times, and we also

might want it in one place, in case we need to change part of it.

Page 116: Responsive Design Tools & Resources

@mixin rounded-top { -moz-border-radius-top: 10px; -webkit-border-top-radius: 10px; border-top-radius: 10px;}

#navbar li { @include rounded-top; }#footer { @include rounded-top; }

The part at the top is where we declare the mixin, “rounded-top.” The part at the bottom is where we are using the mixin,

applying that set of styles to both #navbar li and #footer.

Page 117: Responsive Design Tools & Resources

#navbar li { -moz-border-radius-top: 10px; -webkit-border-top-radius: 10px; border-top-radius: 10px;}#footer { -moz-border-radius-top: 10px; -webkit-border-top-radius: 10px; border-top-radius: 10px;}

When the code is processed, this is what we end up with.

Page 118: Responsive Design Tools & Resources

Math

When you’re doing responsive design, math is one of the most useful functions of a preprocessor.

Page 119: Responsive Design Tools & Resources

.sidebar { width: percentage(360px / 960px);}

Instead of getting out our calculator to figure out percentages for widths, we can just write the original numbers into our code.

Page 120: Responsive Design Tools & Resources

.sidebar { width: 37.5%; }

When it’s processed, the preprocessor figures out the percentage for us and puts it in the CSS.

Page 121: Responsive Design Tools & Resources

@media Bubbling

@media bubbling is like nesting, but for media queries. So this is handy for responsive design. It can keep your stylesheets easier to understand.

Page 122: Responsive Design Tools & Resources

.profile-pic { float: left; width: 250px; @media screen and (max-width: 320px) { width: 100px; } @media screen and (min-width: 1200px) { float: none; }}

In this example, we’re applying different CSS to profile-pic, depending on the viewport width. Everything is inside profile-pic.

Page 123: Responsive Design Tools & Resources

.profile-pic { float: left; width: 250px; @media screen and (max-width: 320px) { width: 100px; } @media screen and (min-width: 1200px) { float: none; }}

These styles apply to profile-pic.

Page 124: Responsive Design Tools & Resources

.profile-pic { float: left; width: 250px; @media screen and (max-width: 320px) { width: 100px; } @media screen and (min-width: 1200px) { float: none; }}

Then here are our media queries, inside! We don’t need to repeat profile-pic, we just need the style.

Page 125: Responsive Design Tools & Resources

.profile-pic {

float: left; width: 250px;

}

@media screen and (max-width: 320px) {

.profile-pic {

width: 100px;

}

}

@media screen and (min-width: 1200px) {

.profile-pic {

float: none;

}

}So when it’s processed, this is what we get: our media queries “bubble” out of the

nest (yes, that’s why it’s called @media bubbling) onto separate lines.

Page 126: Responsive Design Tools & Resources

$break-small: 320px;

$break-large: 1200px;

.profile-pic {

float: left;

width: 250px;

@media screen and (max-width: $break-small) {

width: 100px;

}

@media screen and (min-width: $break-large) {

float: none;

}

}We can also use variables as well, like if we have

breakpoints that are used for various site elements.

Page 127: Responsive Design Tools & Resources

Resources: Preprocessors

Sass And LESS: An Introduction To CSS Preprocessors (Steven Bradley) - April 2012http://www.vanseodesign.com/css/css-preprocessors/

An Introduction To LESS, And Comparison To Sass (Jeremy Hixon) - September 2011http://coding.smashingmagazine.com/2011/09/09/an-introduction-to-less-and-comparison-to-sass/

Responsive Web Design in Sass: Using Media Queries in Sass 3.2 (Mason Wendell) - April 2012http://thesassway.com/intermediate/responsive-web-design-in-sass-using-media-queries-in-sass-32

Create faster fluid layouts with LESS (Paul Mist) - August 2012http://www.netmagazine.com/tutorials/create-faster-fluid-layouts-less

Page 128: Responsive Design Tools & Resources

Responsive images are quite a hot topic lately.

Responsive Images

Page 129: Responsive Design Tools & Resources

img, object, video { max-width: 100%}

We all know that we use max-width: 100% so that our images/media can change size but will always fit within their containing element. The problem is that this means the image we upload to the site has to be the largest size that it will ever display as on the site. We can’t scale

up images, they’ll get blurry. We can only scale them down.

Page 130: Responsive Design Tools & Resources

Performance

So then we’re wasting a lot of bandwidth, forcing users to download images that are much larger than what they might need for a particular device/screen size.

And also, how do we serve up the appropriate images for retina screens without wasting all that bandwidth on devices that don’t need HD images?

Page 131: Responsive Design Tools & Resources

<picture>

The <picture> element has been proposed, but they’re still hammering out the details, so you can’t use it yet. But I’m going to tell you how it will likely work, and then tell you what you can do in the meantime.

http://www.w3.org/community/respimg/

Page 132: Responsive Design Tools & Resources

<picture> <source srcset="small-1.jpg 1x, small-2.jpg 2x"> <source media="(min-width: 18em)" srcset="med-1.jpg 1x, med-2.jpg 2x"> <source media="(min-width: 45em)" srcset="large-1.jpg 1x, large-2.jpg 2x"> <img src="small-1.jpg"></picture>

This is what the code will look like, when we want to display an image on our site.

Page 133: Responsive Design Tools & Resources

<picture> <source srcset="small-1.jpg 1x, small-2.jpg 2x"> <source media="(min-width: 18em)" srcset="med-1.jpg 1x, med-2.jpg 2x"> <source media="(min-width: 45em)" srcset="large-1.jpg 1x, large-2.jpg 2x"> <img src="small-1.jpg"></picture>

This part of the code pretty much works the same as a media query, telling the browser to display a different image based on the viewport width.

Page 134: Responsive Design Tools & Resources

<picture> <source srcset="small-1.jpg 1x, small-2.jpg 2x"> <source media="(min-width: 18em)" srcset="med-1.jpg 1x, med-2.jpg 2x"> <source media="(min-width: 45em)" srcset="large-1.jpg 1x, large-2.jpg 2x"> <img src="small-1.jpg"></picture>

So not only are there different images for each width (small, med, large), there are also versions for regular (1x) and HD (2x).

Page 135: Responsive Design Tools & Resources

<picture> <source srcset="small-1.jpg 1x, small-2.jpg 2x"> <source media="(min-width: 18em)" srcset="med-1.jpg 1x, med-2.jpg 2x"> <source media="(min-width: 45em)" srcset="large-1.jpg 1x, large-2.jpg 2x"> <img src="small-1.jpg"></picture>

Then, for older browsers that won’t support the new <picture> element, there’s a fallback, using <img>, which the older browsers do support.

Page 136: Responsive Design Tools & Resources

Different Images

But it’s not just different sizes of the same image: you may actually want to display different images.

Page 137: Responsive Design Tools & Resources

For example, the image on the wide version of this site wouldn’t look nearly as good at a smaller size. So instead, they choose to use a different crop of the same

image. Sometimes, you may want to display a different image entirely.

http://www.ottersurfboards.co.uk/

Page 138: Responsive Design Tools & Resources

Picturefill

Picturefill is a way for you to have all that functionality now.

Page 139: Responsive Design Tools & Resources

What’s a Polyfill?

Picturefill is a “polyfill.” That’s a piece of code that fills in to do something in older browsers that is only natively possible in newer browsers. For

example, a polyfilll can make older versions of IE do all the things we wish they could do. But there is a downside: using a polyfill adds extra code to your site, so there’s more to download and more to process. Think about

whether you really need to do the cool new functionality in every browser.

Page 140: Responsive Design Tools & Resources

Picturefill is available on Github.

https://github.com/scottjehl/picturefill

Page 141: Responsive Design Tools & Resources

<div data-picture data-alt="Your alt text.">

<div data-src="/img/small.jpg"></div>

<div data-src="/img/medium.jpg" data-media="(min-width: 500px)"></div>

<div data-src="/img/large.jpg" data-media="(min-width: 1000px)"></div>

<!-- Fallback content for non-JS browsers. Same img src as the initial, unqualified source element. -->

<noscript>

<img src="/img/small.jpg" alt="Your alt text.">

</noscript>

</div>

We’ll need to upload some JavaScript to our site. Then this is the code we use to add an image to our site.

Page 142: Responsive Design Tools & Resources

<div data-picture data-alt="Your alt text.">

<div data-src="/img/small.jpg"></div>

<div data-src="/img/medium.jpg" data-media="(min-width: 500px)"></div>

<div data-src="/img/large.jpg" data-media="(min-width: 1000px)"></div>

<!-- Fallback content for non-JS browsers. Same img src as the initial, unqualified source element. -->

<noscript>

<img src="/img/small.jpg" alt="Your alt text.">

</noscript>

</div>

Similar to what I showed you previously, we’re linking to multiple versions of the image (or different images).

Page 143: Responsive Design Tools & Resources

<div data-picture data-alt="Your alt text.">

<div data-src="/img/small.jpg"></div>

<div data-src="/img/medium.jpg" data-media="(min-width: 500px)"></div>

<div data-src="/img/large.jpg" data-media="(min-width: 1000px)"></div>

<!-- Fallback content for non-JS browsers. Same img src as the initial, unqualified source element. -->

<noscript>

<img src="/img/small.jpg" alt="Your alt text.">

</noscript>

</div>

Then we tell the browser which ones should be displayed at different viewport widths.

Page 144: Responsive Design Tools & Resources

<div data-picture data-alt="Your alt text.">

<div data-src="/img/small.jpg"></div>

<div data-src="/img/medium.jpg" data-media="(min-width: 500px)"></div>

<div data-src="/img/large.jpg" data-media="(min-width: 1000px)"></div>

<!-- Fallback content for non-JS browsers. Same img src as the initial, unqualified source element. -->

<noscript>

<img src="/img/small.jpg" alt="Your alt text.">

</noscript>

</div>

If the browser doesn’t support JavaScript, Picturefill won’t work. So you use <noscript> to serve a fallback image.

Page 145: Responsive Design Tools & Resources

<div data-picture data-alt="Your alt text.">

<div data-src="/img/small.jpg"></div>

<div data-src="/img/medium.jpg" data-media="(min-width: 500px)"></div>

<div data-src="/img/large.jpg" data-media="(min-width: 1000px)"></div>

<!--[if (lt IE 9) & (!IEMobile)]>

<div data-src="medium.jpg"></div>

<![endif]-->

<!-- Fallback content for non-JS browsers. Same img src as the initial, unqualified source element. -->

<noscript>

<img src="/img/small.jpg" alt="Your alt text.">

</noscript>

</div>

Then there’s older IE, which won’t do the media query part of the code. So we’ll use conditional comments to give it the appropriate image.

Page 146: Responsive Design Tools & Resources

HD/Retina

HD/retina screens have twice as many pixels in each direction (horizontal, vertical) so you actually need an image that uses 4 times as

many pixels, in order to take full advantage of the HD screen.

Page 147: Responsive Design Tools & Resources

<div data-src="medium.jpg" data-media="(min-width: 400px)"></div>

<div data-src="medium_x2.jpg" data-media="(min-width: 400px) and (min-device-pixel-ratio: 2.0)"></div>

Picturefill supports image replacement for retina. We have two versions of the image.

Page 148: Responsive Design Tools & Resources

<div data-src="medium.jpg" data-media="(min-width: 400px)"></div>

<div data-src="medium_x2.jpg" data-media="(min-width: 400px) and (min-device-pixel-ratio: 2.0)"></div>

They both have the same minimum width query.

Page 149: Responsive Design Tools & Resources

<div data-src="medium.jpg" data-media="(min-width: 400px)"></div>

<div data-src="medium_x2.jpg" data-media="(min-width: 400px) and (min-device-pixel-ratio: 2.0)"></div>

But this one has an additional query of minimum device pixel ratio. So the second image will be served if it’s a HD display.

Page 150: Responsive Design Tools & Resources

Adaptive Images

Adaptive Images is a totally different way to approach the issue of serving multiple sizes of an image.

Page 151: Responsive Design Tools & Resources

http://adaptive-images.com/

Implement this code, and it will detect the screen size, and then create and serve the appropriate re-scaled version of the image. We only need to upload

the largest version of the image. The server does the rest of the work.

Page 152: Responsive Design Tools & Resources

Apache & PHP

One caveat: it only works on sites running Apache and PHP. However, if that is your site, you can use this solution without changing the actual HTML you use for images (unlike with Picturefill). So it’s very easy to implement.

Plus, you can use it on top of any CMS, since it doesn’t change your HTML.

Page 153: Responsive Design Tools & Resources

<?php

$resolutions = array(1382, 992, 768, 480); // the resolution break-points to use (screen widths, in pixels)

...

To set it up, we’ll need to edit the .htaccess file for our site. We’ll then upload a PHP file, changing a few numbers in the file

to match the actual breakpoints we’re using on our site.

Page 154: Responsive Design Tools & Resources

<script>document.cookie='resolution='+Math.max(screen.width,screen.height)+'; path=/';</script>

Then we’ll add this JavaScript in the <head> of our site. As the page starts to load, the JavaScript writes a session cookie to store the user’s screen

size. The way websites work is that as a page is loading, when the browser encounters an <img> tag, it sends a request to the server for the image.

Page 155: Responsive Design Tools & Resources

<IfModule mod_rewrite.c>

  Options +FollowSymlinks

  RewriteEngine On

  RewriteCond %{REQUEST_URI} !assets

  RewriteCond %{REQUEST_URI} !ai-cache

  RewriteRule \.(?:jpe?g|gif|png)$ adaptive-images.php

</IfModule>

Before sending the image back to the browser, the server looks at the .htaccess file to see if there are any special instructions.

Page 156: Responsive Design Tools & Resources

<IfModule mod_rewrite.c>

  Options +FollowSymlinks

  RewriteEngine On

  RewriteCond %{REQUEST_URI} !assets

  RewriteCond %{REQUEST_URI} !ai-cache

  RewriteRule \.(?:jpe?g|gif|png)$ adaptive-images.php

</IfModule>

In this case, we added special instructions in .htaccess, telling it that if the server is being asked for an image file, it should go

to adaptive-images.php instead of just serving the image.

Page 157: Responsive Design Tools & Resources

$resolutions = array(1382, 992, 768, 480); // the resolution break-points to use (screen widths, in pixels)

The adaptive-images.php file looks at the cookie (remember, it stored the user’s screen size), and figures out which size image it should serve, based on the

breakpoints we set earlier. It serves the original image if appropriate, or else creates a scaled-down copy of the image. The scaled-down image will be cached for later use, so the server won’t need to make the same image size over and over again.

Page 158: Responsive Design Tools & Resources

This is an example from the Adaptive Images website. The various versions of the image range from 14 KB to 82 KB. So you’re saving a lot of bandwidth by serving smaller images where you can. Adaptive Images can also handle HD images, you just need to adjust the JavaScript a bit.

http://adaptive-images.com/

Page 159: Responsive Design Tools & Resources

Other Image Solutions

Responsive Imageshttps://github.com/filamentgroup/Responsive-Images

Retina.jshttp://retinajs.com/

FitVids.js (video)http://fitvidsjs.com/

Page 160: Responsive Design Tools & Resources

Resources: Responsive Images

W3C Responsive Images Community Grouphttp://www.w3.org/community/respimg/

Which responsive images solution should you use? - May 2012http://css-tricks.com/which-responsive-images-solution-should-you-use/

Responsive Images and Web Standards at the Turning Point (Mat Marquis) - May 2012http://www.alistapart.com/articles/responsive-images-and-web-standards-at-the-turning-point/

Compressive Images (Scott Jehl) - October 2012http://filamentgroup.com/lab/rwd_img_compression/

Page 161: Responsive Design Tools & Resources

Responsive Data Tables

Data tables can be kind of tricky. If there’s a lot of data, how do you fit it on a small screen? There are many ways you can

do this; I’m going to show you two different options.

Page 162: Responsive Design Tools & Resources

Responsive Tables uses CSS/JavaScript to change the display of the table. This is what your table will look like on a wide screen.

http://www.zurb.com/playground/responsive-tables

Page 163: Responsive Design Tools & Resources

At a narrow width, it pins the first column (which is likely headings/labels), and puts a scrollbar on the rest of it.

http://www.zurb.com/playground/responsive-tables

Page 164: Responsive Design Tools & Resources

<link rel="stylesheet" href="responsive-tables.css">

<script src="responsive-tables.js"></script>

To use this, we just need to upload the CSS and JavaScript files to our site.

Page 165: Responsive Design Tools & Resources

<table class="responsive"> <tr> …

And then add the “responsive” class to any table we want to make responsive. That’s it.

Page 166: Responsive Design Tools & Resources

http://css-tricks.com/examples/ResponsiveTables/responsive.php

Here’s a totally different approach, from CSS-Tricks. This is a table at full width.

Page 167: Responsive Design Tools & Resources

When we make the screen narrow, what happens is that the data is displayed one row at a time, with the labels showing

up over and over, so we know what the data refers to.http://css-tricks.com/examples/ResponsiveTables/responsive.php

Page 168: Responsive Design Tools & Resources

It’s hard to explain, so look at the screenshot. This is what you see when you scroll further down the page.

http://css-tricks.com/examples/ResponsiveTables/responsive.php

Page 169: Responsive Design Tools & Resources

@media only screen and (max-width: 760px), (min-device-width: 768px) and (max-device-width: 1024px) {

! /* Force table to not be like tables anymore */

! table, thead, tbody, th, td, tr {

! ! display: block;

! }

! /* Hide table headers (but not display: none;, for accessibility) */

! thead tr {

! ! position: absolute;

! ! top: -9999px;

! ! left: -9999px;

! }

! td {

! ! /* Behave like a "row" */

! ! border: none;

! ! border-bottom: 1px solid #eee;

! ! position: relative;

! ! padding-left: 50%;

! }

The implementation is quite a bit more complicated than the previous example. In the CSS, we’re basically making each table cell into a row.

Page 170: Responsive Design Tools & Resources

! td:before {

! ! /* Now like a table header */

! ! position: absolute;

! ! /* Top/left values mimic padding */

! ! top: 6px;

! ! left: 6px;

! ! width: 45%;

! ! padding-right: 10px;

! ! white-space: nowrap;

! }

! /* Label the data */

! td:nth-of-type(1):before { content: "First Name"; }

! td:nth-of-type(2):before { content: "Last Name"; }

! td:nth-of-type(3):before { content: "Job Title"; }

! td:nth-of-type(4):before { content: "Favorite Color"; }

! td:nth-of-type(5):before { content: "Wars of Trek?"; }

! td:nth-of-type(6):before { content: "Porn Name"; }

! td:nth-of-type(7):before { content: "Date of Birth"; }

! td:nth-of-type(8):before { content: "Dream Vacation City"; }

! td:nth-of-type(9):before { content: "GPA"; }

! td:nth-of-type(10):before { content: "Arbitrary Data"; }

}

And then we use :before to make the labels show up adjacent to the data for every item. We have to manually enter the labels into the stylesheet for each table, so this can end up being a lot of work.

Page 171: Responsive Design Tools & Resources

Resources: Responsive Tables

A Responsive Design Approach for Complex, Multicolumn Data Tableshttp://filamentgroup.com/lab/responsive_design_approach_for_complex_multicolumn_data_tables/

Responsive Data Tables with jQueryhttp://mobifreaks.com/coding/responsive-data-tables-jquery/

Responsive Patterns: Table Patternshttp://bradfrost.github.com/this-is-responsive/patterns.html#tables

Responsive Data Tables and Screen Reader Accessibility (Jason Kiss) - August 2011http://www.accessibleculture.org/articles/2011/08/responsive-data-tables-and-screen-reader-accessibility/

Page 172: Responsive Design Tools & Resources

Polyfills

I mentioned polyfills earlier. You can make older browsers do what newer browsers do. That being said, responsive design is about being responsive to the

device and the browser, not about having your site look exactly the same on every device. So if you start out building your site with the basics first and doing progressive enhancement, rather than starting out with the most complicated version of the site and doing graceful degradation, you’ll find that you don’t

always need to make the older browsers act like the newer browsers.

Page 173: Responsive Design Tools & Resources

Modernizr is a JavaScript library that detects whether a user’s browser can take advantage of particular features in HTML5 and CSS3. You just need to

upload a JavaScript file, and then call it from the <head> of the page.

http://modernizr.com/

Page 174: Responsive Design Tools & Resources

<html class=" js canvas canvastext geolocation crosswindowmessaging no-websqldatabase indexeddb hashchange historymanagement draganddrop websockets rgba hsla multiplebgs backgroundsize borderimage borderradius boxshadow opacity cssanimations csscolumns cssgradients no-cssreflections csstransforms no-csstransforms3d csstransitions video audio localstorage sessionstorage webworkers applicationcache svg smil svgclippaths fontface">

When the page renders, the JavaScript adds classes to the <html> tag to show which HTML5/CSS3 features are supported. So you’ll get something different here

based on the browser, and then you can use it to pick what CSS is applied.

Page 175: Responsive Design Tools & Resources

For example, in the latest version of Firefox, there are only a few that are not supported. They have “no-” before the feature. Keep

in mind these are all now CSS classes on your page.

<html class=" js canvas canvastext geolocation crosswindowmessaging no-websqldatabase indexeddb hashchange historymanagement draganddrop websockets rgba hsla multiplebgs backgroundsize borderimage borderradius boxshadow opacity cssanimations csscolumns cssgradients no-cssreflections csstransforms no-csstransforms3d csstransitions video audio localstorage sessionstorage webworkers applicationcache svg smil svgclippaths fontface">

Page 176: Responsive Design Tools & Resources

This is what I get in IE7.

<HTML class=" js no-canvas no-canvastext no-geolocation no-crosswindowmessaging no-websqldatabase no-indexeddb no-hashchange no-historymanagement draganddrop no-websockets no-rgba no-hsla no-multiplebgs no-backgroundsize no-borderimage no-borderradius no-boxshadow no-opacity no-cssanimations no-csscolumns no-cssgradients no-cssreflections no-csstransforms no-csstransforms3d no-csstransitions fontface no-video no-audio no-localstorage no-sessionstorage no-webworkers no-applicationcache no-svg no-smil no-svgclippaths">

Page 177: Responsive Design Tools & Resources

<HTML class=" js no-canvas no-canvastext no-geolocation no-crosswindowmessaging no-websqldatabase no-indexeddb no-hashchange no-historymanagement draganddrop no-websockets no-rgba no-hsla no-multiplebgs no-backgroundsize no-borderimage no-borderradius no-boxshadow no-opacity no-cssanimations no-csscolumns no-cssgradients no-cssreflections no-csstransforms no-csstransforms3d no-csstransitions fontface no-video no-audio no-localstorage no-sessionstorage no-webworkers no-applicationcache no-svg no-smil no-svgclippaths">

Yep, a whole lotta NOs.

Page 178: Responsive Design Tools & Resources

.no-boxshadow { ...}

So let’s say we happen to be using boxshadow in our site design. We can add CSS to do something different only for browsers that don’t support

boxshadow. We might want to use a polyfill to replicate behavior, or if that part of the style isn’t essential to the design, we might just need some

simple CSS to accommodate the difference in the design.

Page 179: Responsive Design Tools & Resources

This is a great site: they’ve collected links to all the different polyfills you can use to replicate various HTML5 functionality in older browsers.

https://github.com/Modernizr/Modernizr/wiki/HTML5-Cross-browser-Polyfills

Page 180: Responsive Design Tools & Resources

Respond is one particular polyfill I want to point out. It enables max-width and min-width media queries in browsers that don’t

support them. (IE8 and older, particularly)https://github.com/scottjehl/Respond

Page 181: Responsive Design Tools & Resources

<!--[if lte IE 8]><script src=”js/respond.min.js”/></script><![endif]-->

You just need to upload the JavaScript file, and then link to it from your <head> using a conditional comment.

Page 182: Responsive Design Tools & Resources

More Resources

Page 184: Responsive Design Tools & Resources

Books to Read

Responsive Web DesignEthan Marcotte (2011)http://www.abookapart.com/products/responsive-web-design/

Mobile First Luke Wroblewski (2011)http://www.abookapart.com/products/mobile-first

Adaptive Web Design: Crafting Rich Experiences with Progressive EnhancementAaron Gustafson (2011)http://easy-readers.net/books/adaptive-web-design/

Implementing Responsive Design: Building sites for an anywhere, everywhere webTim Kadlec (2012)http://www.implementingresponsivedesign.com/

Page 185: Responsive Design Tools & Resources

Other Websites & Misc.

@RWDlinks about responsive design (Ethan Marcotte)https://twitter.com/RWD

Future Friendlymaking things that are future-friendlyhttp://futurefriend.ly/

Brad Frostblog that covers responsive designhttp://bradfrostweb.com/blog/

Mediaqueri.esinspirational websites using media queries and responsive web designhttp://mediaqueri.es/

Page 186: Responsive Design Tools & Resources

If you were actually at the CWSA event (Oct. 30, 2012), you’ll recognize “Flo” from the Progressive lobby. And that’s me on the

left. It’s been my lifelong dream to pose for a picture next to a cardboard cutout of “Flo.” I can now cross it off my bucket list.

Page 187: Responsive Design Tools & Resources

*Also if you were at the CWSA event, and arrived in time for the warm-up act, you will appreciate this resource:

My Hermit Crab is Not Moving - Is He Molting or Is He Dead?http://exoticpets.about.com/od/hermitcrabs/f/hcmoltordead.htm

Photo credit: Jessica Diamond via Creative Commons http://flic.kr/p/4T5miW