Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS

responsive web design issuess

hi everybody

What is grid system and indeed why need to use it in responsive web design, and also how do i need to adapt it in html+css theme making? Thank you

2 Answers

Nikolaos Papathanassopoulos
Nikolaos Papathanassopoulos
10,322 Points

A grid-based-system is not an obligation for a responsive site. But it can be very useful Tool.

A grid is a group of defined classes which are used to set the width of a page-element.

For example: If you're using a grid with 10 Columns, and your site has a defined max-width of 1000px; each column would take an additional 10 % of the pages width.

.grid_1 { width: 10%; } /* 100px/1000px = 0.1 */
.grid_2 { width: 20%; } /* 200px/1000px = 0.2 */
.grid_3 { width: 30%; } /* 300px/1000px = 0.3 */
.grid_4 { width: 40%; } /* 400px/1000px = 0.4 */
.grid_5 { width: 50%; } /* 500px/1000px = 0.5 */
.grid_6 { width: 60%; } /* 600px/1000px = 0.6 */
.grid_7 { width: 70%; } /* 700px/1000px = 0.7 */
.grid_8 { width: 80%; } /* 800px/1000px = 0.8 */
.grid_9 { width: 90%; } /* 900px/1000px = 0.9 */
.grid_10 { width: 100%; } /* 1000px/1000px = 1.0 */

// Basic example for a 10-column-grid.

If you want to give your site a certain pagelayout its very easy to adjust widths. You just have to add the specific class to a 'div' element.

For example:

A two column layout inside a container:

<div id="container" class="grid_10">
    <div class="grid_5"></div>
    <div class="grid_5"></div>
</div>

A five-column layout inside a container:

<div id="container" class="grid_10">
    <div class="grid_2"></div>
    <div class="grid_2"></div>
    <div class="grid_2"></div>
    <div class="grid_2"></div>
    <div class="grid_2"></div>
</div>

This process saves time!

Don't forget to add some margin in your grid to have a little gutter / bufferzone between your page elements:

grid_1, 
grid_2, 
grid_3, 
grid_4, 
grid_5, 
grid_6, 
grid_7, 
grid_8, 
grid_9, 
grid_10{
    margin: 1% 1% 1% 1%; // Set the margin how you like it best.
    float: left;
}

If you do this, make sure to remove the margin-width from your grid-classes:

.grid_1 { width: 8%; } /* 80px/1000px = 0.08 */
.grid_2 { width: 18%; } /* 180px/1000px = 0.18 */
.grid_3 { width: 28%; } /* 280px/1000px = 0.28 */
.grid_4 { width: 38%; } /* 380px/1000px = 0.38 */
.grid_5 { width: 48%; } /* 480px/1000px = 0.48 */
.grid_6 { width: 58%; } /* 580px/1000px = 0.58 */
.grid_7 { width: 68%; } /* 680px/1000px = 0.68 */
.grid_8 { width: 78%; } /* 780px/1000px = 0.78 */
.grid_9 { width: 88%; } /* 880px/1000px = 0.88 */
.grid_10 { width: 98%; } /* 980px/1000px = 0.98 */

// 10-column grid with gutter of 20px or 2%

~ Nikos.

very nice nikos , ur steps are very very very clear.^^ no lie, really very good