¿Eres nuevo? ¡Lee el FAQ y ponte al día!
9k visitas

Introduction to 960 Grid System

What is a grid system?

It may seem complicated, but a grid system is just a CSS file that defines a set of styles that help to organize the contents of your website. You can think of it as a grid sheet.

Woo Themes Grid

In the image above, you can see how woothemes.com has used the 960 Grid System; all the elements in the page fit in the grid.

How to use a Grid System?

It is really easy: The first thing you need to do is to download a .css file that will contain the 960 Grid System. You have two options to get it:

  1. You can create a personalized version from this site: Variable Grid System. The good thing about this method is that you can customize the grid to your own needs. I recommend to use this method and, judging by the huge link in their website, the creators of the 960 GS are OK with that.
  2. You can download the official version from their repository. At the same time, you will obtain some examples and documentation, but you will not have the same flexibility that the Variable Grid System offers.

Variable Grid System

For this example, I have created a twelve columns grid with 50 pixels wide columns and a gutter width of 30 pixels. Once you have downloaded it, you need to put the grid.css file in the folder where you are working. Also, put in that folder the initial HTML and CSS files with the following content:

example.css:

CSS
  1. body, html { background-color: #fffff4; color: #333; font-family: Georgia, Times New Roman, Serif; }
  2.  
  3. h1 { display: none; }
  4.  
  5. h2 { font-weight: normal; font-size: xx-large; }
  6.  
  7. a { color: #0ad2b9; }
  8. a:hover { color: #2d695f; }
  9.  
  10. /* teaser and hello texts at index */
  11.  
  12. .hello { font-size: 90px; margin: 30px 0; }
  13.  
  14. .teaser { font-size: 45px; margin: 10px 0; line-height: 125%; }
  15. .teaser a { color: #0ad2b9; text-decoration: none; }
  16. .teaser a:hover { background-color: white; }
  17.  
  18. /* facebook badge */
  19.  
  20. .facebook_badge { margin-top: 25px; text-align: center; }
  21.  
  22. /* long texts */
  23.  
  24. .long_text { text-align: justify; }
  25.  

­

example.html:

HTML
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2.    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3.  
  4.     <head>
  5.  
  6.         <title>Introduction to 960 Grid System</title>
  7.  
  8.         <link rel="stylesheet" href="example.css" type="text/css" media="screen" charset="utf-8" />
  9.         <link rel="stylesheet" href="grid.css" type="text/css" media="screen" charset="utf-8" />
  10.  
  11.         <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  12.  
  13.     </head>
  14.  
  15.     <body>
  16.  
  17.         <h1 class="heading">The personal blog of Miguel Santirso</h1>
  18.  
  19.         <div>
  20.  
  21.             <div>
  22.                 <p class="heading hello">Hello!</p>
  23.                 <p class="heading teaser">I am <a href="http://miguelsantirso.es/">Miguel Santirso</a> and this is a test using the <a href="http://960.gs">960 Grid System</a>:</p>
  24.             </div>
  25.  
  26.             <div>
  27.                 <div class="facebook_badge">
  28.                     <!-- Facebook Badge START --><a href="http://www.facebook.es/miguel.santirso" title="Miguel Santirso González" target="_TOP"><img src="http://badge.facebook.com/badge/718517613.289.164519491.png" width="120" height="247" style="border: 0px;" /></a><!-- Facebook Badge END -->
  29.                 </div>
  30.             </div>
  31.  
  32.             <div>
  33.                 <h2>Some projects I am working on:</h2>
  34.             </div>
  35.  
  36.             <div>
  37.                 <h3>The Source Cookbook</h3>
  38.  
  39.                 <p class="long_text"><a href="http://sourcecookbook.com/">The Source Cookbook</a> is a place to show and keep your source code snippets. The recipes can be embedded everywhere and are beautifully highlighted for every language.</p>
  40.             </div>
  41.  
  42.             <div>
  43.                 <h3>ululand.com - Play Better</h3>
  44.  
  45.                 <p class="long_text"><a href="http://ululand.com/">ululand</a> is a better flash games portal. At ululand you can play the same great flash games, only better: Save your scores, create competitions and much more.</p>
  46.             </div>
  47.  
  48.         </div>
  49.  
  50.     </body>
  51. </html>
  52.  

­

And this is how it should look before using the grid to give some structure to the content:

The content before using the grid

Now that we have some dummy content, we can start using the grid system to give a good structure to this content with almost zero effort.

Let's start with the top of the page. I want to place the facebook badge at the top left of the page. To get that, I just need to apply a few styles from the grid system:

HTML
  1. <div class="container_12">
  2.  
  3.     <div class="grid_10 push_2">
  4.         <p class="heading hello">Hello!</p>
  5.         <p class="heading teaser">I am <a href="http://miguelsantirso.es/">Miguel Santirso</a> and this is a test using the <a href="http://960.gs">960 Grid System</a>:</p>
  6.     </div>
  7.  
  8.     <div class="grid_2 pull_10">
  9.         <div class="facebook_badge">
  10.             <!-- Facebook Badge START --><a href="http://www.facebook.es/miguel.santirso" title="Miguel Santirso González" target="_TOP"><img src="http://badge.facebook.com/badge/718517613.289.164519491.png" width="120" height="247" style="border: 0px;" /></a><!-- Facebook Badge END -->
  11.         </div>
  12.     </div>
  13.  

­

The container_12 class activates the grid styles in all the elements inside that div.

grid_10 means that a > div should be 10 columns wide and grid_2 means 2 columns wide. In general, you can use grid_1 to grid_12 styles to set the widths of the elements on the page.

push_2 pushes an element two columns to the right and pull_10 pulls the element ten columns to the left.

Notice that, if you want to use the whole the width of the page, all divs inside a container_12 should have a total width of 12 columns, as you may have expected.

You should have something like this:

First content structured

Now, you just need to use the same technique to style the rest of the page:

HTML
  1. <div class="grid_10 prefix_2">
  2.     <h2>Some projects I am working on:</h2>
  3. </div>
  4.  
  5. <div class="grid_5 prefix_2">
  6.     <h3>The Source Cookbook</h3>
  7.  
  8.     <p class="long_text"><a href="http://sourcecookbook.com/">The Source Cookbook</a> is a place to show and keep your source code snippets. The recipes can be embedded everywhere and are beautifully highlighted for every language.</p>
  9. </div>
  10.  
  11. <div class="grid_5">
  12.     <h3>ululand.com - Play Better</h3>
  13.  
  14.     <p class="long_text"><a href="http://ululand.com/">ululand</a> is a better flash games portal. At ululand you can play the same great flash games, only better: Save your scores, create competitions and much more.</p>
  15. </div>
  16.  

­

And here is the final result:

The final result

As a conclusion:

As a conclusion, I would like to emphasize that the 960 Grid System is a simple, easy and powerful way to organize the content of your sites if you don't want to spend a lot of time or you just are not very experienced with CSS.

If you have any doubts or anything to comment on this article, you can contact me at twitter (@miguelSantirso) or by e-mail: miguel.santirso at gmail.

Etiquetas: CSS HTML 960.gs web web design grid system

Insertar: