├── .gitignore
├── README.md
├── bower.json
├── grid.css
├── images
├── border.png
├── box-model.png
├── container.png
├── content.png
├── desktop-first.png
├── fragmentation.png
├── margin.png
├── mobile-first.png
├── mobile.png
├── padding.png
├── small-large.png
├── with-box-model.png
└── without-box-model.png
├── index.html
└── normalize.css
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | wdnr.sublime-project
3 | wdnr.sublime-workspace
4 | node_modules
5 | .sass-cache
6 | .sublime-grunt.cache
7 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Grid is a great learning tool but no longer supported. [Learn why](http://adamkaplan.me/blog/grid-retrospective).
2 |
3 |
4 | ## Grid
5 |
6 | A simple guide to responsive design.
7 | www.adamkaplan.me/grid
8 |
9 | #### Why bother with responsive?
10 | We want our websites to be useable on all devices by responding to the user’s behavior, screen size and screen orientation.
11 |
12 | #### A Fragmented World
13 | 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.
14 |
15 | #### Mobile First
16 | 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!
17 |
18 | > 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
19 |
20 | ## Min-width Media Queries
21 | 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.
22 |
23 | ```css
24 | /* Small screens (default) */
25 | html { font-size: 100%; }
26 |
27 | /* Medium screens (640px) */
28 | @media (min-width: 40rem) {
29 | html { font-size: 112%; }
30 | }
31 |
32 | /* Large screens (1024px) */
33 | @media (min-width: 64rem) {
34 | html { font-size: 120%; }
35 | }
36 | ```
37 |
38 | ## Steps
39 |
40 | #### 1. Not All Browsers are Created Equal
41 | 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](http://necolas.github.io/normalize.css/), which will render elements more consistently cross-browser. Remember to include it as-is before your stylesheet.
42 |
43 | ```html
44 |
45 |
46 | ```
47 |
48 | #### 2. Add the Viewport Meta Tag
49 | Place in the `
` of your HTML. This enables use of media queries for cross-device layouts.
50 | ```html
51 |
52 | ```
53 |
54 | #### 3. Use box-sizing: border-box
55 | Place at the top of your CSS file. The `*` will target all elements on the page.
56 | ```css
57 | *, *:before, *:after {
58 | -moz-box-sizing: border-box;
59 | -webkit-box-sizing: border-box;
60 | box-sizing: border-box;
61 | }
62 | ```
63 |
64 | #### 4. Create a Container
65 | A container holds all elements and controls the page's maximum width. Using a container will make designing for responsive easier!
66 | ```css
67 | .container {
68 | margin: 0 auto;
69 | max-width: 48rem;
70 | width: 90%;
71 | }
72 | ```
73 |
74 | ```html
75 |
76 |
77 |
78 | ```
79 |
80 | #### 5. Create a Column
81 | With mobile first, columns are `block` level (takes up the full width available) by default. No additional styles needed!
82 |
83 | ```html
84 |
85 |
86 |
87 |
88 |
89 | ```
90 |
91 | #### 6. Create Column Sizes
92 | 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.
93 |
94 | ```html
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 | ```
106 |
107 | ```css
108 | @media (min-width: 40rem) {
109 | .column {
110 | float: left;
111 | padding-left: 1rem;
112 | padding-right: 1rem;
113 | }
114 |
115 | .column.full { width: 100%; }
116 | .column.two-thirds { width: 66.7%; }
117 | .column.half { width: 50%; }
118 | .column.third { width: 33.3%; }
119 | .column.fourth { width: 25%; }
120 | .column.flow-opposite { float: right; }
121 | }
122 | ```
123 |
124 | #### 7. Create Rows
125 | Columns are wrapped in rows to prevent other elements from stacking next to them, otherwise know as clearing issues. Rows are cleared using the popular `clearfix`, which was created by [Nicolas Gallagher](http://nicolasgallagher.com/micro-clearfix-hack/).
126 |
127 | ```html
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 | ```
148 |
149 | ```css
150 | .clearfix:before,
151 | .clearfix:after {
152 | content: " ";
153 | display: table;
154 | }
155 |
156 | .clearfix:after {
157 | clear: both;
158 | }
159 |
160 | .clearfix {
161 | *zoom: 1;
162 | }
163 | ```
164 |
165 | #### Flow Opposite
166 | Add the class `.flow-opposite` to columns where you want content to display first on mobile but appear on the right on larger screens.
167 |
168 | ```html
169 |
A simple guide to responsive design. Made by Adam Kaplan.
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
Why bother with responsive?
39 |
We want our websites to be useable on all devices by responding to
40 | the user’s behavior, screen size and screen orientation.
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
A Fragmented World
51 |
As of 2013, there are thousands
52 | of different devices and screen sizes that browse the internet, so it’s impossible to design layouts to target them
53 | all. Instead, we must take a more fluid approach to design.
54 |
55 |
56 |
57 |
58 |
59 |
Mobile First
60 |
The term “mobile first” gets thrown around a lot lately. What it really means is to start with mobile
61 | styles and layer on styles optimized for larger screens only as needed. In other words, your mobile styles become
62 | the default and you no longer have to override them later. It’s much simpler!
63 |
64 |
65 |
By assuming a flexible but simple layout by default, you can better guard against browsers—with viewports wide
66 | and small—that aren’t quite capable of the full responsive layout. So when we’re talking about layout, “mobile first”
67 | really means “progressive enhancement.”
68 | —Ethan Marcotte
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
Min-width Media Queries
82 |
Introduce layout-specific rules only when you need them. Use min-width to layer complexity on your
83 | layout as the viewport widens. It’s easier to have all the media queries nearby, rather than at the end
84 | of the stylesheet or in a separate document.
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
1
93 |
Not All Browsers are Created Equal
94 |
Browsers will render your CSS differently. To avoid this, it’s a good idea to use a modern
95 | alternative to a reset like Normalize.css,
96 | which will render elements more consistently cross-browser. Remember to include it as-is before your stylesheet.
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
2
105 |
Add the Viewport Meta Tag
106 |
Place in the <head> of your HTML. This enables use of media queries for cross-device layouts.
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
CSS Box Model
121 |
It’s important to understand the basics, like how elements are generated and behave in the browser, before
122 | diving into responsive web design. The CSS Box Model consists of four distinct parts.
123 |
124 |
125 |
126 |
127 |
128 |
Content
129 |
The content of the box, where text and images appear.
130 |
131 |
132 |
133 |
134 |
Padding
135 |
Clears an area around the content.
136 |
137 |
138 |
139 |
140 |
Border
141 |
A border that goes around the padding.
142 |
143 |
144 |
145 |
146 |
Margin
147 |
Clears an area around the border.
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
3
156 |
Use box-sizing: border-box
157 |
Place at the top of your CSS file. The * will target all elements on the page.
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
Your Choice
166 |
What was once a bug
167 | is now a widely used CSS property. It basically means you can choose whether or not to include borders and padding in
168 | the width of your content.
169 |
170 |
171 |
172 |
173 |
174 |
Without box-sizing: border-box
175 |
Margin, borders and padding are drawn outside the set width of your content.
176 |
177 |
178 |
179 |
180 |
With box-sizing: border-box
181 |
Borders and padding are drawn inside the set width of your content. The margin is drawn outside.
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
4
190 |
Create a Container
191 |
A container holds all elements and controls the page’s maximum width. Using a container will make designing for
192 | responsive easier!
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
5
208 |
Create a Column
209 |
With mobile first, columns are block level (takes up the full width available) by default. No
210 | additional styles needed!
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 | .column
220 |
221 |
222 |
223 | .column
224 |
225 |
226 |
227 | .column
228 |
229 |
230 |
231 | .column
232 |
233 |
234 |
235 |
236 |
237 |
238 |
6
239 |
Create Column Sizes
240 |
On larger screens, columns gain float: left in order to stack content horizontally. Columns now
241 | use padding for gutters, so you no longer need to worry about removing margins.
242 |
243 |
244 |
245 |
246 |
247 |
248 | .column .half
249 |
250 |
251 |
252 | .column .half
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 | .column .full
268 |
269 |
270 |
271 |
272 |
273 | .column .two-thirds
274 |
275 |
276 |
277 | .column .third
278 |
279 |
280 |
281 |
282 |
283 | .column .half
284 |
285 |
286 |
287 | .column .half
288 |
289 |
290 |
291 |
292 |
293 | .column .third
294 |
295 |
296 |
297 | .column .third
298 |
299 |
300 |
301 | .column .third
302 |
303 |
304 |
305 |
306 |
307 | .column .fourth
308 |
309 |
310 |
311 | .column .fourth
312 |
313 |
314 |
315 | .column .fourth
316 |
317 |
318 |
319 | .column .fourth
320 |
321 |
322 |
323 |
324 |
325 |
326 |
327 |
7
328 |
Create Rows
329 |
Columns are wrapped in rows to prevent other elements from stacking next to them, otherwise known as clearing
330 | issues. Rows are cleared using the popular clearfix, which was created by
331 | Nicolas Gallagher.
332 |
333 |
334 |
335 |
336 |
337 |
338 |
339 |
340 |
341 |
342 | .column .half
343 |
344 |
345 |
346 | .column .half
347 |
348 |
349 |
350 |
351 |
352 | .column .half
353 |
354 |
355 |
356 | .column .half
357 |
358 |
359 |
360 |
361 |
362 |
363 |
364 |
Flow Opposite
365 |
Add the class .flow-opposite to columns where you want content to display first on mobile but
366 | appear on the right on larger screens.
367 |
368 |
369 |
370 |
371 |
372 |
373 |
374 |
375 |
376 |
377 | .column .half .flow-opposite
378 |
379 |
380 |
381 | .column .half
382 |
383 |
384 |
385 |
386 |
387 |
388 |
389 |
Practice Makes Perfect
390 |
By following these simple steps, you are on the path to responsive
391 | web design mastery. Keep practicing and help make the web a better,
392 | more useable place.