├── .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 |
170 |
171 |
172 | 173 |
174 |
175 | 176 |
177 |
178 |
179 | ``` 180 | 181 | ```css 182 | @media (min-width: 40rem) { 183 | .column.flow-opposite { float: right; } 184 | } 185 | ``` 186 | 187 | #### Further Reading 188 | * [A Book Apart: Mobile First](http://www.abookapart.com/products/mobile-first) 189 | * [A Book Apart: Responsive Web Design](http://www.abookapart.com/products/responsive-web-design) 190 | * [Beginner’s Guide to Responsive Web Design](http://blog.teamtreehouse.com/beginners-guide-to-responsive-web-design) 191 | * [Box-sizing: Border-box FTW](http://www.paulirish.com/2012/box-sizing-border-box-ftw/) 192 | * [Don't Forget the Viewport Meta Tag](http://dev.tutsplus.com/articles/quick-tip-dont-forget-the-viewport-meta-tag--webdesign-5972) 193 | * [The Many Faces of ‘Mobile First’](http://bradfrostweb.com/blog/mobile/the-many-faces-of-mobile-first/) 194 | * [Understanding the Humble Clearfix](http://fuseinteractive.ca/blog/understanding-humble-clearfix) 195 | 196 | #### References 197 | * [Android Fragmentation Visualized](http://opensignal.com/reports/fragmentation-2013/) 198 | * [Animate.css](http://daneden.github.io/animate.css/) 199 | * [Box Model](http://developer.mozilla.org/en-US/docs/Web/CSS/box_model) 200 | * [Chrome Developer Tools](http://developers.google.com/chrome-developer-tools/) 201 | * [Code samples by GitHub Gist](https://gist.github.com/aekaplan) 202 | * [Internet Explorer Box Model](http://en.wikipedia.org/wiki/Internet_Explorer_box_model_bug) 203 | * [Progressive Enhancement](http://coding.smashingmagazine.com/2009/04/22/progressive-enhancement-what-it-is-and-how-to-use-it/) 204 | 205 | ## Translations 206 | Translations are maintained by their creators and may not always be up to date with the original here. Have a translation you'd like to link to? Open a pull request to add it here. Be sure to keep it alphabetical. 207 | 208 | * [Chinese](http://geekplux.github.io/grid) - Translated by [GeekPlux](http://www.geekplux.com/) 209 | * [Japanese](http://maepon.github.io/grid/) - Translated by [Masayuki Maekawa](http://maepon.skpn.com/) 210 | * [Portuguese](http://webfatorial.github.io/grid/) - Translated by [webfatorial](http://webfatorial.com/) 211 | * [Türkçe](http://eminarslan.github.io/grid/) - Çeviren [eminarslan](http://eminarslan.com/) 212 | * [Ukrainian](http://ivaskevytch.github.io/grid/) - Translated by Ivaskevytch 213 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "aekaplan-grid", 3 | "version": "1.0.0", 4 | "main": "grid.css", 5 | "author": "Adam Kaplan", 6 | "ignore": [ 7 | "README.md", 8 | "index.html" 9 | ] 10 | } -------------------------------------------------------------------------------- /grid.css: -------------------------------------------------------------------------------- 1 | /* Layout 2 | ========================================================================== */ 3 | 4 | *, *:before, *:after { 5 | -moz-box-sizing: border-box; 6 | -webkit-box-sizing: border-box; 7 | box-sizing: border-box; 8 | } 9 | 10 | html { 11 | font: 100%/1.5 "Open Sans", sans-serif; 12 | font-weight: 400; 13 | text-rendering: optimizeLegibility; 14 | -webkit-font-smoothing: antialiased; 15 | } 16 | 17 | @media (min-width: 40rem) { 18 | html { font-size: 112%; } 19 | } 20 | 21 | @media (min-width: 64rem) { 22 | html { font-size: 120%; } 23 | } 24 | 25 | body { 26 | background-color: #fff; 27 | color: #555; 28 | } 29 | 30 | .container { 31 | margin: 0 auto; 32 | max-width: 53rem; 33 | width: 90%; 34 | } 35 | 36 | /* Header 37 | ========================================================================== */ 38 | 39 | header { 40 | background-color: #497bad; 41 | text-align: center; 42 | } 43 | 44 | .intro { margin: 2rem 0; } 45 | 46 | @media (min-width: 40rem) { 47 | .intro { margin: 4rem 0; } 48 | } 49 | 50 | header h1 { 51 | border: 3px solid #fff; 52 | -moz-border-radius: 3px; 53 | -webkit-border-radius: 3px; 54 | border-radius: 3px; 55 | color: #fff; 56 | padding: .4rem .6rem; 57 | display: inline-block; 58 | font-size: 1.8rem; 59 | text-transform: uppercase; 60 | margin-bottom: 2rem; 61 | } 62 | 63 | header p { 64 | color: rgba(255,255,255,0.7); 65 | margin: 0 auto; 66 | } 67 | 68 | header a { 69 | color: rgba(255,255,255,0.9); 70 | text-decoration: underline; 71 | } 72 | 73 | header a:hover { text-decoration: none; } 74 | 75 | .mobile { 76 | margin: 0 auto; 77 | max-width: 150px; 78 | } 79 | 80 | @media (min-width: 40rem) { 81 | .mobile { max-width: 250px; } 82 | } 83 | 84 | /* Section 85 | ========================================================================== */ 86 | 87 | section { 88 | border-top: 1px solid #eee; 89 | text-align: center; 90 | padding: 2rem 0; 91 | } 92 | 93 | section:first-of-type { border-top: none; } 94 | 95 | @media (min-width: 40rem) { 96 | section { padding: 4rem 0; } 97 | } 98 | 99 | /* Mobile First Grid 100 | ========================================================================== */ 101 | 102 | .column { margin-bottom: 1.5rem; } 103 | 104 | @media (min-width: 40rem) { 105 | .column { 106 | float: left; 107 | margin: 0; 108 | padding-left: 1rem; 109 | padding-right: 1rem; 110 | } 111 | 112 | .column.full { width: 100%; } 113 | .column.two-thirds { width: 66.7%; } 114 | .column.half { width: 50%; } 115 | .column.third { width: 33.3%; } 116 | .column.fourth { width: 25%; } 117 | .column.flow-opposite { float: right; } 118 | } 119 | 120 | /* Typography 121 | ========================================================================== */ 122 | 123 | h1, h2, h3, h4, h5 { 124 | font-weight: 600; 125 | margin: 0; 126 | } 127 | 128 | h1 { 129 | font-size: 1.3rem; 130 | line-height: 1.3em; 131 | margin-bottom: 1.5rem; 132 | } 133 | 134 | @media (min-width: 40rem) { 135 | h1 { font-size: 1.5rem; } 136 | } 137 | 138 | h3 { 139 | font-size: 1.2rem; 140 | margin-bottom: .5rem; 141 | } 142 | 143 | p { 144 | color: #999; 145 | margin: 0 auto; 146 | max-width: 30rem; 147 | } 148 | 149 | blockquote { margin: 0; } 150 | 151 | blockquote p { 152 | color: #bbb; 153 | font-style: italic; 154 | margin-bottom: 1.5rem; 155 | } 156 | 157 | cite { color: #bbb; } 158 | 159 | /* Code 160 | ========================================================================== */ 161 | 162 | code { 163 | background-color: #f8f8f8; 164 | -moz-border-radius: 3px; 165 | -webkit-border-radius: 3px; 166 | border-radius: 3px; 167 | border: 1px solid #ddd; 168 | font-family: Consolas, "Liberation Mono", Courier, monospace; 169 | font-size: 0.8rem; 170 | padding: 0.1rem 0.3rem; 171 | position: relative; 172 | top: -1px; 173 | white-space: nowrap; 174 | } 175 | 176 | /* Lists 177 | ========================================================================== */ 178 | 179 | ul { 180 | margin: 0; 181 | text-align: left; 182 | } 183 | 184 | @media (min-width: 40rem) { 185 | ul { display: inline-block; } 186 | } 187 | 188 | /* Links 189 | ========================================================================== */ 190 | 191 | a { 192 | color: #497bad; 193 | text-decoration: none; 194 | } 195 | 196 | a:hover { text-decoration: underline; } 197 | 198 | /* Buttons 199 | ========================================================================== */ 200 | 201 | .button { 202 | -moz-appearance: none; 203 | -webkit-appearance: none; 204 | appearance: none; 205 | background-color: #497bad; 206 | -moz-border-radius: 3px; 207 | -webkit-border-radius: 3px; 208 | border-radius: 3px; 209 | border: none; 210 | color: #fff; 211 | cursor: pointer; 212 | display: block; 213 | font-size: 1rem; 214 | font-weight: 600; 215 | padding: 0.7rem 1.5rem; 216 | vertical-align: middle; 217 | white-space: nowrap; 218 | } 219 | 220 | .button:hover { 221 | background: #5183b6; 222 | text-decoration: none; 223 | } 224 | 225 | @media (min-width: 40rem) { 226 | .button { 227 | display: inline-block; 228 | font-size: 0.9rem; 229 | } 230 | } 231 | 232 | /* Elements 233 | ========================================================================== */ 234 | 235 | hr { 236 | border: 0; 237 | border-top: 1px solid #ddd; 238 | margin: 2rem auto; 239 | width: 3rem; 240 | } 241 | 242 | @media (min-width: 40rem) { 243 | hr { margin: 2.5rem auto; } 244 | } 245 | 246 | hr.small { margin: 1.5rem auto; } 247 | 248 | .circle { 249 | border: 3px solid #555; 250 | border-radius: 50%; 251 | -moz-border-radius: 50%; 252 | -webkit-border-radius: 50%; 253 | color: #555; 254 | display: block; 255 | font-size: 1.7rem; 256 | font-weight: 600; 257 | height: 3.2rem; 258 | line-height: 1.7em; 259 | margin: 0 auto 1rem auto; 260 | text-align: center; 261 | width: 3.2rem; 262 | } 263 | 264 | img { 265 | display: block; 266 | height: auto; 267 | margin: 0 auto 1.5rem auto; 268 | width: 100%; 269 | } 270 | 271 | .rwd { 272 | margin: 0 auto 1.5rem auto; 273 | max-width: 440px; 274 | } 275 | 276 | /* Examples 277 | ========================================================================== */ 278 | 279 | .example { 280 | border-top: none; 281 | background-color: #497bad; 282 | color: #fff; 283 | } 284 | 285 | .example p { color: rgba(255,255,255,0.7); } 286 | .example img { margin: 0; } 287 | 288 | .fragmentation { 289 | background-image: url("/images/fragmentation.png"); 290 | background-size: cover; 291 | min-height: 250px; 292 | } 293 | 294 | @media (min-width: 40rem) { 295 | .fragmentation { min-height: 500px; } 296 | } 297 | 298 | .mobile-first .column { 299 | float: none; 300 | margin-bottom: 1rem; 301 | } 302 | 303 | .grid { text-align: center; } 304 | 305 | .grid span { 306 | background: rgba(225,255,255,0.1); 307 | border: 2px solid rgba(255,255,255,0.2); 308 | display: block; 309 | padding: 1rem; 310 | font-size: 0.9rem; 311 | font-weight: 600; 312 | } 313 | 314 | .grid .container { 315 | border: 2px dashed rgba(255,255,255,0.3); 316 | padding: 1rem 1rem 0 1rem; 317 | } 318 | 319 | @media (min-width: 40rem) { 320 | .grid .container { padding: 1rem 0 0 0; } 321 | } 322 | 323 | .grid .column { margin-bottom: 1rem; } 324 | 325 | .row-example .container { 326 | border: 2px dashed rgba(255,255,255,0.2); 327 | padding: 1rem; 328 | } 329 | 330 | .row-example .row { 331 | background: rgba(225,255,255,0.1); 332 | border: 2px solid rgba(255,255,255,0.2); 333 | padding: 1rem 1rem 0 1rem; 334 | margin-bottom: 1rem; 335 | } 336 | 337 | .row-example .row:last-of-type { margin-bottom: 0; } 338 | 339 | @media (min-width: 40rem) { 340 | .row-example .row { padding: 1rem 0 0 0; } 341 | } 342 | 343 | .gutters { 344 | border: 2px dashed #eee; 345 | margin-bottom: 2rem; 346 | max-width: 39rem; 347 | padding: 1rem 1rem 0 1rem; 348 | } 349 | 350 | .gutters .column { 351 | background: #fb917e; 352 | margin-bottom: 1rem; 353 | } 354 | 355 | .gutters span { 356 | background: #f8f8f8; 357 | color: #999; 358 | display: block; 359 | padding: 1rem 0; 360 | } 361 | 362 | /* Box Model 363 | ========================================================================== */ 364 | 365 | .box-model h1 { margin-bottom: 3rem; } 366 | 367 | .margin { color: #f9cd9d; } 368 | .border { color: #fce08f; } 369 | .padding { color: #c2ddb6; } 370 | .content { color: #9ec3e5; } 371 | 372 | /* Gist Overrides 373 | ========================================================================== */ 374 | 375 | .gist .gist-file { 376 | font-size: .9rem !important; 377 | margin: 0 auto; 378 | max-width: 39rem; 379 | overflow: hidden !important; 380 | text-align: left; 381 | } 382 | 383 | .gist .gist-file .gist-data { 384 | background: #f8f8f8 !important; 385 | border-bottom: none !important; 386 | } 387 | 388 | .gist .gist-file .gist-meta { 389 | display: none !important; 390 | } 391 | 392 | .gist-syntax .k { 393 | color: #555 !important; 394 | font-weight: normal !important; 395 | } 396 | 397 | /* Animate.css by Daniel Eden 398 | ========================================================================== */ 399 | 400 | .animated{-webkit-animation-fill-mode:both;-moz-animation-fill-mode:both;-ms-animation-fill-mode:both;-o-animation-fill-mode:both;animation-fill-mode:both;-webkit-animation-duration:2s;-moz-animation-duration:2s;-ms-animation-duration:2s;-o-animation-duration:2s;animation-duration:2s;}.animated.hinge{-webkit-animation-duration:2s;-moz-animation-duration:2s;-ms-animation-duration:2s;-o-animation-duration:2s;animation-duration:2s;}@-webkit-keyframes fadeInUp { 401 | 0% { 402 | opacity: 0; 403 | -webkit-transform: translateY(20px); 404 | } 100% { 405 | opacity: 1; 406 | -webkit-transform: translateY(0); 407 | } 408 | } 409 | 410 | @-moz-keyframes fadeInUp { 411 | 0% { 412 | opacity: 0; 413 | -moz-transform: translateY(20px); 414 | } 415 | 416 | 100% { 417 | opacity: 1; 418 | -moz-transform: translateY(0); 419 | } 420 | } 421 | 422 | @-o-keyframes fadeInUp { 423 | 0% { 424 | opacity: 0; 425 | -o-transform: translateY(20px); 426 | } 427 | 428 | 100% { 429 | opacity: 1; 430 | -o-transform: translateY(0); 431 | } 432 | } 433 | 434 | @keyframes fadeInUp { 435 | 0% { 436 | opacity: 0; 437 | transform: translateY(20px); 438 | } 439 | 440 | 100% { 441 | opacity: 1; 442 | transform: translateY(0); 443 | } 444 | } 445 | 446 | .fadeInUp { 447 | -webkit-animation-name: fadeInUp; 448 | -moz-animation-name: fadeInUp; 449 | -o-animation-name: fadeInUp; 450 | animation-name: fadeInUp; 451 | } 452 | 453 | /* Utilities 454 | ========================================================================== */ 455 | 456 | .remove-padding { padding-bottom: 0; } 457 | .remove-border { border: none; } 458 | 459 | /* Clearfix by Nicolas Gallagher 460 | ========================================================================== */ 461 | 462 | .clearfix:before, 463 | .clearfix:after { 464 | content: " "; 465 | display: table; 466 | } 467 | 468 | .clearfix:after { clear: both; } 469 | .clearfix { *zoom: 1; } 470 | -------------------------------------------------------------------------------- /images/border.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aekaplan/grid/5a653fb1c80735a1b978244ca831e15615ab8fff/images/border.png -------------------------------------------------------------------------------- /images/box-model.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aekaplan/grid/5a653fb1c80735a1b978244ca831e15615ab8fff/images/box-model.png -------------------------------------------------------------------------------- /images/container.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aekaplan/grid/5a653fb1c80735a1b978244ca831e15615ab8fff/images/container.png -------------------------------------------------------------------------------- /images/content.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aekaplan/grid/5a653fb1c80735a1b978244ca831e15615ab8fff/images/content.png -------------------------------------------------------------------------------- /images/desktop-first.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aekaplan/grid/5a653fb1c80735a1b978244ca831e15615ab8fff/images/desktop-first.png -------------------------------------------------------------------------------- /images/fragmentation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aekaplan/grid/5a653fb1c80735a1b978244ca831e15615ab8fff/images/fragmentation.png -------------------------------------------------------------------------------- /images/margin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aekaplan/grid/5a653fb1c80735a1b978244ca831e15615ab8fff/images/margin.png -------------------------------------------------------------------------------- /images/mobile-first.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aekaplan/grid/5a653fb1c80735a1b978244ca831e15615ab8fff/images/mobile-first.png -------------------------------------------------------------------------------- /images/mobile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aekaplan/grid/5a653fb1c80735a1b978244ca831e15615ab8fff/images/mobile.png -------------------------------------------------------------------------------- /images/padding.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aekaplan/grid/5a653fb1c80735a1b978244ca831e15615ab8fff/images/padding.png -------------------------------------------------------------------------------- /images/small-large.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aekaplan/grid/5a653fb1c80735a1b978244ca831e15615ab8fff/images/small-large.png -------------------------------------------------------------------------------- /images/with-box-model.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aekaplan/grid/5a653fb1c80735a1b978244ca831e15615ab8fff/images/with-box-model.png -------------------------------------------------------------------------------- /images/without-box-model.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aekaplan/grid/5a653fb1c80735a1b978244ca831e15615ab8fff/images/without-box-model.png -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Grid 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 |
27 |
28 |

grid

29 |

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

30 |
31 | Intro 32 |
33 |
34 | 35 |
36 |
37 | Mobile First 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 | Mobile First 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 | Box Model 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 | content 128 |

Content

129 |

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

130 |
131 | 132 |
133 | padding 134 |

Padding

135 |

Clears an area around the content.

136 |
137 | 138 |
139 | border 140 |

Border

141 |

A border that goes around the padding.

142 |
143 | 144 |
145 | margin 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 | Without Box Model 174 |

Without box-sizing: border-box

175 |

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

176 |
177 | 178 |
179 | With Box Model 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 | Container 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.

393 |
394 |

View the Code

395 |
396 |
397 | 398 |
399 |
400 | 429 |
430 |
431 | 432 | 433 | -------------------------------------------------------------------------------- /normalize.css: -------------------------------------------------------------------------------- 1 | /*! normalize.css v3.0.0 | MIT License | git.io/normalize */ 2 | 3 | /** 4 | * 1. Set default font family to sans-serif. 5 | * 2. Prevent iOS text size adjust after orientation change, without disabling 6 | * user zoom. 7 | */ 8 | 9 | html { 10 | font-family: sans-serif; /* 1 */ 11 | -ms-text-size-adjust: 100%; /* 2 */ 12 | -webkit-text-size-adjust: 100%; /* 2 */ 13 | } 14 | 15 | /** 16 | * Remove default margin. 17 | */ 18 | 19 | body { 20 | margin: 0; 21 | } 22 | 23 | /* HTML5 display definitions 24 | ========================================================================== */ 25 | 26 | /** 27 | * Correct `block` display not defined in IE 8/9. 28 | */ 29 | 30 | article, 31 | aside, 32 | details, 33 | figcaption, 34 | figure, 35 | footer, 36 | header, 37 | hgroup, 38 | main, 39 | nav, 40 | section, 41 | summary { 42 | display: block; 43 | } 44 | 45 | /** 46 | * 1. Correct `inline-block` display not defined in IE 8/9. 47 | * 2. Normalize vertical alignment of `progress` in Chrome, Firefox, and Opera. 48 | */ 49 | 50 | audio, 51 | canvas, 52 | progress, 53 | video { 54 | display: inline-block; /* 1 */ 55 | vertical-align: baseline; /* 2 */ 56 | } 57 | 58 | /** 59 | * Prevent modern browsers from displaying `audio` without controls. 60 | * Remove excess height in iOS 5 devices. 61 | */ 62 | 63 | audio:not([controls]) { 64 | display: none; 65 | height: 0; 66 | } 67 | 68 | /** 69 | * Address `[hidden]` styling not present in IE 8/9. 70 | * Hide the `template` element in IE, Safari, and Firefox < 22. 71 | */ 72 | 73 | [hidden], 74 | template { 75 | display: none; 76 | } 77 | 78 | /* Links 79 | ========================================================================== */ 80 | 81 | /** 82 | * Remove the gray background color from active links in IE 10. 83 | */ 84 | 85 | a { 86 | background: transparent; 87 | } 88 | 89 | /** 90 | * Improve readability when focused and also mouse hovered in all browsers. 91 | */ 92 | 93 | a:active, 94 | a:hover { 95 | outline: 0; 96 | } 97 | 98 | /* Text-level semantics 99 | ========================================================================== */ 100 | 101 | /** 102 | * Address styling not present in IE 8/9, Safari 5, and Chrome. 103 | */ 104 | 105 | abbr[title] { 106 | border-bottom: 1px dotted; 107 | } 108 | 109 | /** 110 | * Address style set to `bolder` in Firefox 4+, Safari 5, and Chrome. 111 | */ 112 | 113 | b, 114 | strong { 115 | font-weight: bold; 116 | } 117 | 118 | /** 119 | * Address styling not present in Safari 5 and Chrome. 120 | */ 121 | 122 | dfn { 123 | font-style: italic; 124 | } 125 | 126 | /** 127 | * Address variable `h1` font-size and margin within `section` and `article` 128 | * contexts in Firefox 4+, Safari 5, and Chrome. 129 | */ 130 | 131 | h1 { 132 | font-size: 2em; 133 | margin: 0.67em 0; 134 | } 135 | 136 | /** 137 | * Address styling not present in IE 8/9. 138 | */ 139 | 140 | mark { 141 | background: #ff0; 142 | color: #000; 143 | } 144 | 145 | /** 146 | * Address inconsistent and variable font size in all browsers. 147 | */ 148 | 149 | small { 150 | font-size: 80%; 151 | } 152 | 153 | /** 154 | * Prevent `sub` and `sup` affecting `line-height` in all browsers. 155 | */ 156 | 157 | sub, 158 | sup { 159 | font-size: 75%; 160 | line-height: 0; 161 | position: relative; 162 | vertical-align: baseline; 163 | } 164 | 165 | sup { 166 | top: -0.5em; 167 | } 168 | 169 | sub { 170 | bottom: -0.25em; 171 | } 172 | 173 | /* Embedded content 174 | ========================================================================== */ 175 | 176 | /** 177 | * Remove border when inside `a` element in IE 8/9. 178 | */ 179 | 180 | img { 181 | border: 0; 182 | } 183 | 184 | /** 185 | * Correct overflow displayed oddly in IE 9. 186 | */ 187 | 188 | svg:not(:root) { 189 | overflow: hidden; 190 | } 191 | 192 | /* Grouping content 193 | ========================================================================== */ 194 | 195 | /** 196 | * Address margin not present in IE 8/9 and Safari 5. 197 | */ 198 | 199 | figure { 200 | margin: 1em 40px; 201 | } 202 | 203 | /** 204 | * Address differences between Firefox and other browsers. 205 | */ 206 | 207 | hr { 208 | -moz-box-sizing: content-box; 209 | box-sizing: content-box; 210 | height: 0; 211 | } 212 | 213 | /** 214 | * Contain overflow in all browsers. 215 | */ 216 | 217 | pre { 218 | overflow: auto; 219 | } 220 | 221 | /** 222 | * Address odd `em`-unit font size rendering in all browsers. 223 | */ 224 | 225 | code, 226 | kbd, 227 | pre, 228 | samp { 229 | font-family: monospace, monospace; 230 | font-size: 1em; 231 | } 232 | 233 | /* Forms 234 | ========================================================================== */ 235 | 236 | /** 237 | * Known limitation: by default, Chrome and Safari on OS X allow very limited 238 | * styling of `select`, unless a `border` property is set. 239 | */ 240 | 241 | /** 242 | * 1. Correct color not being inherited. 243 | * Known issue: affects color of disabled elements. 244 | * 2. Correct font properties not being inherited. 245 | * 3. Address margins set differently in Firefox 4+, Safari 5, and Chrome. 246 | */ 247 | 248 | button, 249 | input, 250 | optgroup, 251 | select, 252 | textarea { 253 | color: inherit; /* 1 */ 254 | font: inherit; /* 2 */ 255 | margin: 0; /* 3 */ 256 | } 257 | 258 | /** 259 | * Address `overflow` set to `hidden` in IE 8/9/10. 260 | */ 261 | 262 | button { 263 | overflow: visible; 264 | } 265 | 266 | /** 267 | * Address inconsistent `text-transform` inheritance for `button` and `select`. 268 | * All other form control elements do not inherit `text-transform` values. 269 | * Correct `button` style inheritance in Firefox, IE 8+, and Opera 270 | * Correct `select` style inheritance in Firefox. 271 | */ 272 | 273 | button, 274 | select { 275 | text-transform: none; 276 | } 277 | 278 | /** 279 | * 1. Avoid the WebKit bug in Android 4.0.* where (2) destroys native `audio` 280 | * and `video` controls. 281 | * 2. Correct inability to style clickable `input` types in iOS. 282 | * 3. Improve usability and consistency of cursor style between image-type 283 | * `input` and others. 284 | */ 285 | 286 | button, 287 | html input[type="button"], /* 1 */ 288 | input[type="reset"], 289 | input[type="submit"] { 290 | -webkit-appearance: button; /* 2 */ 291 | cursor: pointer; /* 3 */ 292 | } 293 | 294 | /** 295 | * Re-set default cursor for disabled elements. 296 | */ 297 | 298 | button[disabled], 299 | html input[disabled] { 300 | cursor: default; 301 | } 302 | 303 | /** 304 | * Remove inner padding and border in Firefox 4+. 305 | */ 306 | 307 | button::-moz-focus-inner, 308 | input::-moz-focus-inner { 309 | border: 0; 310 | padding: 0; 311 | } 312 | 313 | /** 314 | * Address Firefox 4+ setting `line-height` on `input` using `!important` in 315 | * the UA stylesheet. 316 | */ 317 | 318 | input { 319 | line-height: normal; 320 | } 321 | 322 | /** 323 | * It's recommended that you don't attempt to style these elements. 324 | * Firefox's implementation doesn't respect box-sizing, padding, or width. 325 | * 326 | * 1. Address box sizing set to `content-box` in IE 8/9/10. 327 | * 2. Remove excess padding in IE 8/9/10. 328 | */ 329 | 330 | input[type="checkbox"], 331 | input[type="radio"] { 332 | box-sizing: border-box; /* 1 */ 333 | padding: 0; /* 2 */ 334 | } 335 | 336 | /** 337 | * Fix the cursor style for Chrome's increment/decrement buttons. For certain 338 | * `font-size` values of the `input`, it causes the cursor style of the 339 | * decrement button to change from `default` to `text`. 340 | */ 341 | 342 | input[type="number"]::-webkit-inner-spin-button, 343 | input[type="number"]::-webkit-outer-spin-button { 344 | height: auto; 345 | } 346 | 347 | /** 348 | * 1. Address `appearance` set to `searchfield` in Safari 5 and Chrome. 349 | * 2. Address `box-sizing` set to `border-box` in Safari 5 and Chrome 350 | * (include `-moz` to future-proof). 351 | */ 352 | 353 | input[type="search"] { 354 | -webkit-appearance: textfield; /* 1 */ 355 | -moz-box-sizing: content-box; 356 | -webkit-box-sizing: content-box; /* 2 */ 357 | box-sizing: content-box; 358 | } 359 | 360 | /** 361 | * Remove inner padding and search cancel button in Safari and Chrome on OS X. 362 | * Safari (but not Chrome) clips the cancel button when the search input has 363 | * padding (and `textfield` appearance). 364 | */ 365 | 366 | input[type="search"]::-webkit-search-cancel-button, 367 | input[type="search"]::-webkit-search-decoration { 368 | -webkit-appearance: none; 369 | } 370 | 371 | /** 372 | * Define consistent border, margin, and padding. 373 | */ 374 | 375 | fieldset { 376 | border: 1px solid #c0c0c0; 377 | margin: 0 2px; 378 | padding: 0.35em 0.625em 0.75em; 379 | } 380 | 381 | /** 382 | * 1. Correct `color` not being inherited in IE 8/9. 383 | * 2. Remove padding so people aren't caught out if they zero out fieldsets. 384 | */ 385 | 386 | legend { 387 | border: 0; /* 1 */ 388 | padding: 0; /* 2 */ 389 | } 390 | 391 | /** 392 | * Remove default vertical scrollbar in IE 8/9. 393 | */ 394 | 395 | textarea { 396 | overflow: auto; 397 | } 398 | 399 | /** 400 | * Don't inherit the `font-weight` (applied by a rule above). 401 | * NOTE: the default cannot safely be changed in Chrome and Safari on OS X. 402 | */ 403 | 404 | optgroup { 405 | font-weight: bold; 406 | } 407 | 408 | /* Tables 409 | ========================================================================== */ 410 | 411 | /** 412 | * Remove most spacing between table cells. 413 | */ 414 | 415 | table { 416 | border-collapse: collapse; 417 | border-spacing: 0; 418 | } 419 | 420 | td, 421 | th { 422 | padding: 0; 423 | } --------------------------------------------------------------------------------