Grid is a great learning tool but no longer supported. Learn why.

grid

A simple guide to responsive design.
Made by Adam Kaplan.

Intro
Mobile First

Why bother with responsive?

We want our websites to be useable on all devices by responding to the user’s behavior, screen size and screen orientation.

A Fragmented World

As of 2013, there are thousands of different devices and screen sizes that browse the internet, so it’s impossible to design layouts to target them all. Instead, we must take a more fluid approach to design.

Mobile First

The term “mobile first” gets thrown around a lot lately. What it really means is to start with mobile styles and layer on styles optimized for larger screens only as needed. In other words, your mobile styles become the default and you no longer have to override them later. It’s much simpler!


By assuming a flexible but simple layout by default, you can better guard against browsers—with viewports wide and small—that aren’t quite capable of the full responsive layout. So when we’re talking about layout, “mobile first” really means “progressive enhancement.”

—Ethan Marcotte
Mobile First

Min-width Media Queries

Introduce layout-specific rules only when you need them. Use min-width to layer complexity on your layout as the viewport widens. It’s easier to have all the media queries nearby, rather than at the end of the stylesheet or in a separate document.


1

Not All Browsers are Created Equal

Browsers will render your CSS differently. To avoid this, it’s a good idea to use a modern alternative to a reset like Normalize.css, which will render elements more consistently cross-browser. Remember to include it as-is before your stylesheet.


2

Add the Viewport Meta Tag

Place in the <head> of your HTML. This enables use of media queries for cross-device layouts.


Box Model

CSS Box Model

It’s important to understand the basics, like how elements are generated and behave in the browser, before diving into responsive web design. The CSS Box Model consists of four distinct parts.


content

Content

The content of the box, where text and images appear.

padding

Padding

Clears an area around the content.

border

Border

A border that goes around the padding.

margin

Margin

Clears an area around the border.

3

Use box-sizing: border-box

Place at the top of your CSS file. The * will target all elements on the page.


Your Choice

What was once a bug is now a widely used CSS property. It basically means you can choose whether or not to include borders and padding in the width of your content.


Without Box Model

Without box-sizing: border-box

Margin, borders and padding are drawn outside the set width of your content.

With Box Model

With box-sizing: border-box

Borders and padding are drawn inside the set width of your content. The margin is drawn outside.

4

Create a Container

A container holds all elements and controls the page’s maximum width. Using a container will make designing for responsive easier!


Container
5

Create a Column

With mobile first, columns are block level (takes up the full width available) by default. No additional styles needed!


.column
.column
.column
.column
6

Create Column Sizes

On larger screens, columns gain float: left in order to stack content horizontally. Columns now use padding for gutters, so you no longer need to worry about removing margins.


.column .half
.column .half
.column .full
.column .two-thirds
.column .third
.column .half
.column .half
.column .third
.column .third
.column .third
.column .fourth
.column .fourth
.column .fourth
.column .fourth
7

Create Rows

Columns are wrapped in rows to prevent other elements from stacking next to them, otherwise known as clearing issues. Rows are cleared using the popular clearfix, which was created by Nicolas Gallagher.


.column .half
.column .half
.column .half
.column .half

Flow Opposite

Add the class .flow-opposite to columns where you want content to display first on mobile but appear on the right on larger screens.


.column .half .flow-opposite
.column .half

Practice Makes Perfect

By following these simple steps, you are on the path to responsive web design mastery. Keep practicing and help make the web a better, more useable place.


View the Code