Prototyping With the 360 CSS Framework

Prototyping With The Grid 960 CSS Framework

Tutorial Details
  • Difficulty: Intermediate

Grid 960 is a CSS Framework that enables developers to rapidly prototype designs. They are excellent tools for creating mock ups. Why? Because they do all the heavy lifting allowing you to get faster results.

That sounds nice, but how do we do that? There are a lot of articles on the internet blasting or supporting CSS frameworks, but none have any content to help inexperienced readers decide. This one is different. This article covers the entire prototyping process. Imagine you are given a design and you need a mock up for the client. This article explains the basics of Grid 960, planning the grid for a design, and coding the prototype. The sample design will exploit most capabilities of Grid 960 giving you a firm knowledge base to work on. After you’ve seen the design below, its time to learn about how Grid 960 works.

Final


1. Making the Grid

Grid 960 works by using classes through inheritance. Grid 960 provides two grids: 12 and 16 columns. The main container is always 960px wide. Using 960 allows the most combinations of column while being easy to work with. We will use the 12 column grid to code this design, but we will not use all 12 columns. Every grid cell has a margin: 0 10px. This creates a gutter of 20px. When creating a row, the total width of all elements add up to 960. Take a look at Grid 960′s demo page. You will see a nice grid with all sorts of combinations. Each grid cell has a class that specifies what width it will be. Here is the break down of column widths for a 12 column grid.

  1. 60px
  2. 140px
  3. 220px
  4. 300px
  5. 380px
  6. 460px
  7. 540px
  8. 620px
  9. 700px
  10. 780px
  11. 860px
  12. 940px

Each width corresponds to a class name formed like this: grid_X where X is a number from the above list. If you want a block with width 940 use class grid_12. How does Grid 960 know what width it is supposed to be? Each grid_x is a selector container_Y .grid_X where Y is either 12 or 16 for columns. Lets dive into some code. Here’s how to create a two row grid in a 12 column container. Let the first row be 940px, and the second row contain two equal columns.

<div class="container_12">
	<div class="grid_12"><p>940px</p></div>

	<div class="clear"></div>
	<div class="grid_6"><p>460px</p></div>  
	<div class="grid_6"><p>460px</p></div>

	<div class="clear"></div>
</div>

When creating a row in the grid, make sure all the child grid_X numbers add up to the number of columns you’re using. This ensures the correct width. Two grid_6 div’s add up to 12. You are no limited to the same numbers. You could also use 6, 4, and 2. There you have it, a quick grid ready for content. Now that you know how Grid 960 works, lets see how to create the mockup.


2.The Mock Up

Visualizing the design’s grid is easy. There is one row for the header image, a row for the nav bar, a row with 2 columns for the headline story and poster, a spacer, 4 columns, a spacer, than a footer with 3 columns. Click on the image for the code.

After checking out the visual, you should understand how to create the mockup’s grid. Using the widths, match up the class #’s from the list and lets throw some code together. Remember to add the clearing div at the end of each row. Don’t forget to include the stylsheets included in the Grid 960 package.

<div class="container_12">
	<div class="grid_12"></div>
	<div class="clear"></div>

	
	<div class="grid_12"></div>
	<div class="clear"> </div>
	
	<div class="grid_7"></div>
	<div class="grid_5"></div>

	<div class="clear"></div>
	
	<div class="grid_12"></div>
	<div class="clear"></div>
	
	<div class="grid_3"></div>

	<div class="grid_3"></div>
	<div class="grid_3"></div>
	<div class="grid_3"></div>
	<div class="clear"></div>

	
	<div class="grid_12"></div>
	<div class="clear"></div>
	
	<div class="grid_4"></div>
	<div class="grid_4"></div>

	<div class="grid_4"></div>
</div>

The skeleton is ready. Time to start overlaying the design. The green bars are just divs with a background color and height. The navbar does not have a set height. Instead, it will be controlled by the size of the links inside. Don’t forget to add the header image as well.

	div.spacer {
		background-color: #8FC73E;
		height: 1em;
	}
	
	div#navbar {
		background-color: #8FC73E;
		padding: 10px 0;
	}

Apply the class to correct grid_12 divs and set the ID.


<div class="container_12">
	<div class="grid_12"><a href="images/header.png" alt=""/></div>
	<div class="clear"></div>

	
	<div class="grid_12" id="navbar"></div>
	<div class="clear"> </div>
	
	<div class="grid_7"></div>

	<div class="grid_5"></div>
	<div class="clear"></div>
	
	<div class="grid_12 spacer"></div>
	<div class="clear"></div>

	
	<div class="grid_3"></div>
	<div class="grid_3"></div>
	<div class="grid_3"></div>
	<div class="grid_3"></div>

	<div class="clear"></div>
	
	<div class="grid_12 spacer"></div>
	<div class="clear"></div>
	
	<div class="grid_4"></div>

	<div class="grid_4"></div>
	<div class="grid_4"></div>
</div>

The middle columns don’t require any effects. Add some place holder text to fill out the design. You can make some here. Before tackling the top section, move to the footer. In the screenshot, the footer is a solid color. You cannot accomplish this with the current code. A wrapper div around the bottom three columns solves the problem. So you think, no big deal, just insert a div. That breaks the grid since Grid 960 relies on parents and children to apply the styles (remember the selector container_12 .grid_4?) A subgrid solves the problem. Grid 960 allows nested grids. Create a subgrid by adding a grid_12 div, then place the grid_4′s inside it. When using nested grids the children elements require special classes. The first child needs a class "alpha" and the last child a class &qout;omega" Edit the markup to reflect the changes and apply stylistic changes to the footer.

<div class="grid_12" id="footer">
	<div class="grid_4 alpha"></div>
	<div class="grid_4"></div>

	<div class="grid_4 omega"></div>
</div>
div#footer {
	background-color: #e5e5e6;
}

Excellent! Now the footer has a solid background color and you can adjust the sizes of the columns if needed. Add some dummy text to the footer columns for right now and lets move to navbar. The navbar is a simple unordered list. Add some links and proper styling.


<div class="grid_12" id="navbar"></div>
	<ul>
		<li>Articles</li>
		<li>Topics</li>

		<li>About</li>
		<li>Editors</li>
		<li>Contact</li>
	</ul>

</div>
div#navbar ul {
	list-style: none;
	display: block;
	margin: 0 10px;
}

div#navbar ul li {
	float: left;
	margin: 0 1.5em;
	font: bold 1em Arial;
}

Sweet. The page is really coming together. All that’s left is creating the block effects on the top section. This is more sinister than it appears. Before we diving in, you need to realize some things about Grid 960 and CSS frameworks in general.


3. CSS Frameworks Do Not Solve All Your Problems

Astute readers may have realized something. The page is extremely rigid. Everything has a defined size and changing the size creates problems or potentially breaks the design. Designers also sacrifice some of our design goals because what Grid 960 allows. For example, the sample design was 1000px wide. Grid 960 only creates grids 960px wide, so the extra size is lost. What if you want to make your page 1000px instead of 960? In short, you can’t without doing some heavy modification to the code. The framework locks designers into a set of constraints. Say the client wants a design that is wider or thinner. The designer will most likely have to scrap the code they’ve written to accomplish the new goals. There is another problem that hasn’t been revealed yet–equal height columns. Since the middle columns all share the same background, they appear to be equal heights. In the footer a wrapper div puts a background behind the 3 columns. Grid 960 does not give you equal height columns. There is of course a way you can accomplish this on your own. Since we are prototyping a design, don’t spend time worrying about the finer details on how the design will function when in production. You are only trying to convey the ideas at this stage. There is also another aspect of Grid 960 to take into account before tackling the top section. Grid 960 relies on sized elements and margins to create a correctly sized row. If you apply padding or borders, the design breaks. If you do, you have to adjust the size of the div to reflect the changes. Be weary of this. Adjust the sizes of elements in two places will always lead to confusion and make the design harder to maintain. That being said. Lets finish the top section.


4. The Top Section

Luckily you can maneuver around equal height columns in the top section. Since the image on the right as a set height and width, we know the other column’s size. Create the block effect by adding a new div with a border inside the existing divs. Don’t forget to set the heights. Don’t set padding on the divs because that will change the width of block and break the grid. Instead specify a margin on a child element. This will not change the width of the block. Apply a margin to an inline element. This creates the desired effect and the text wraps to fit.

<div class="grid_7 topSection">
	<div> </div>
</div>
<div class="grid_5 topSection">

</div>

Use a class instead of ID because the topSection class is applied to two divs. This also allows us to change the heights easier. Choose a height (this number is really up to you) and create a class.

div.topSection div {
	border: solid 10px #e5e5e6;
	height: 280px;
}

div.topSection div p {
	margin: 10px;
}

Cool! Lets check out the progress.

Ready to fill the two boxes? Go ahead and fill the left one some with some sample text. Don’t make to much or it will overflow the box. This creates a potential problem in the final design. How do you know how much text is too much? For the production design, the designer would need to create a function to only allow X amount of words to stop the over flow. Time to get the poster image ready. Before inserting an image determine the dimensions. If you are good a math and understanding the box model, you most likely already know how big it should be. If you don’t, fire up FireBug and take a peak into the DOM. Click on Inspect. Get down to the div in question and click on it. Open the Layout tab. FireBug will display a helpful box model reference. Check out the image for help. Click on the image for fullsize.

The screenshot shows the poster div is 360×280. Find an image and create a style. I decided to let the image fill the entire div (unlike in the sample design.) If you wanted to create a 10px margin make sure to reduce the dimensions by 20px on each side.

img#poster {
	width: 360px;
	height: 280px;
}

You should get this. The mockup is complete. Feel free to throw in some real text and change the image around.


5. Know Thy Limits

Now that the prototype is finished,to take stock what has been done. You’ve manage to quickly prototype a design. Grid 960 easily created the grid for us. Where do to go from here? Naturally we would show the client and see what they think. There are a few caveats though. Have you tested this design in IE6 or IE7? No. Should we? No. This is a prototype. This is what it would look like in production. It is natural that any browser quirks would be worked out before production. What if the clients wants to create a more complex design? In this case, you will quickly start to see the limits of the framework. What if the design needs to be liquid or elastic? The framework will no do that. You would need to start from scratch. Remember that CSS Frameworks do not solve all your problems, but they do help with some. Grid 960 as well as others are great for throwing together prototypes. You can just as well use the concepts of Grid 960 in the production code, but it is not recommend sticking with a framework all the way through production. CSS frameworks are just like any tool, they have their uses. With that in mind, go forth and prototype!

Tags: CSS
Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • Phil D

    Thanks,
    this is starting to get my brain into gear to
    understand grid frameworks better –
    Once I learn
    these rules then I figure
    I can creatively
    break them (intentionally).

    I found a link to a hybrid version
    of “blueprint & 960″ floating
    around amongst some search results.
    I’ll probably stick to 960 until I’ve nailed it
    before moving on just yet

  • http://www.dotlancer.com kamal

    Hi
    Thanks very nice info
    dwgeeks.com

  • Shawn Stringfield

    I found this site that is ripping your posts off. Its pulling the exact content from this post and using it as it’s own article:

    http://bangpound.org/node/4105

  • http://www.discoverysquare.co.uk Philip Osborne

    I found a site with all these grid_x classes in the CSS and didn’t know what it was all about … I figured it was some sort of grid system but had never seen it before. You’ve answered a lot of questions here, definitely something I think I’ll be making use of.

    I agree with those comments that say it can be as semantic as you want it … ok, so the classes aren’t very semantic but just add an id to each div and you’re sorted.

    I’m also agreeing with the comments about designers use of layouts. From a developmental point of view I understand the need to separate content from layout and can see why the use of table layouts should be stopped, the html should be purely for content not layout and tables used purely for representing data. However, from a designers point of view I understand the importance of some kind of structured grid system and I’m pleased to see that a way has been found to incorporate this into CSS, maintaining the separation between content and layout but providing us designers with the grid system we find so useful!

  • http://www.digitalspacetech.com Digital Space

    The final screenshot image has this program looks similar to dreamweaver but looks more pro than dreamweaver, can anyone tell me what program it is i want to get one.

    I urgently want to know what editor that is.

    Width regards the grid tut, i dont think it is any use to most designers here, unless as said over and over again that you are working on a newspaper or magazine or portals of any kind for quick visual idea of how things might come out.

    I do not think it is a good idea to get people to use stuff like this, ok it makes life easier for sure, but then people forget about how to code css down the line, so i would say just start from scratch and work your way up so that further down the line when you come across with problems with your layout than you know where the problem is.

    “Buying a car is not a big deal, but building one is.”

    • internq7

      it’s using Firebug add-on for Firefox

  • Pingback: December’s Best: This Month in Web Design | Vandelay Website Design

  • Pingback: December’s Best: This Month in Web Design | Castup

  • Andre

    Nothing beats scratch code, but at some point a designer/developer must pull together a toolbox to get a quality job done swiftly. People that question the efficacy of a framework should remember shortcuts, filters, effects, macros, scripts, snippets, generators, Ruby on Rails, jQuery, etc… Personally, I’m building my own framework for a horizontal aand vertical rhythm using relative units (with scalable image divs). I’d hate to make something like that only to reinvent it for each new project.

  • Pingback: iLoveGray: a free wordpress theme - FrancescoMugnai.com

  • Mike

    @Digital Space

    The last screen shot was of Firefox with Firebug.. its not for editing.

    If you want a good clean editor go with TextMate http://macromates.com/ or Emacs

    • madmax

      try coda

  • Pingback: Moleskine - 960 Grid System, Divine Proportion, Rules of Thirds | John Wang

  • Pingback: 960 Grid System for Rapid Prototyping | Netvivs

  • lawrence farrell

    Terrific! You rock!

  • Pingback: Working With a Content Management Framework: MODx - NETTUTS

  • Pingback: Aurigis » Working With a Content Management Framework: MODx

  • Pingback: Aurigis.com » Blog Archive » Working With a Content Management Framework: MODx

  • simon

    A grid system in css need not have anything to do with the baseline grid, blueprint has tried to cover this , by snapping text to a baseline all text and image elements line up – so if the baseline is 18pt all images need to be a multiple of that figure.

    A grid system need not be tied up with the baseline its just the layout, its nothing to do with the type – don’t restrict the type to a baseline set it free.

  • http://www.e2e.be jbcarey

    Just like every other webdeveloper I’ve tried the grid systems, 960.gs, Bluetrip…. and Usually I only tend to enjoy one thing I get from them and that is their Typograhical side of their frameworks….

    As such I’ve been working on creating a “default template” that I’ve been using for my own site, as well as client site (very handy i’ve you average 2-3 sites a week)…

    What does it for me is that I now “know” that my design works crossbrowser, whereas before I was forced to continually test in a wide array of browsers. If you get to know your own code, and tweak it constantly, it becomes a very powerful tool….

    On a different level it even helps you really stick to a company simply because you are playing by your rules and you are forcing the company to start playing by those rules too…. Very handy if you don’t want to get laid-off during a crisis. :D

  • Pingback: When Should You Use a CSS Framework?

  • Rob

    Thanks Adam! Will you marry me?

  • Pingback: A Detailed Look at the 960 CSS Framework - NETTUTS

  • Pingback: December’s Best: This Month in Web Design :: COMPUTER TREASURE

  • Pingback: Mark’s Link Blog » links for 2009-01-20

  • Pingback: A Detailed Look at the 960 CSS Framework « 7pounds.net

  • http://www.johnpash.com JP

    I think it’s funny that the world is still struggling with hacks and work-arounds and countless tutorials in order to emulate what the TABLE tag does so easily.

    I’ve heard all the arguments for and against, and the jury is out as far as my view. But every time I read yet another article about the frailty and complication of a css based layout, I want to get out a copy of FrontPage 1.1 from 1995 and fill up 20-pixel-bordered tables with reams of Comic Sans and animated GIFS and dump the entire thing on a repeating patterned background! Oh yea, I can’t forget the little digging “under construction” stickman. Life was so simple back then.

  • Pingback: Bookmarks for January 23rd → Quality Peoples

  • V

    @ author – Good tutorial but a bit hard to follow at times. I had to re-read the part about “Apply the class to correct grid_12 divs and set the ID. ” and TopSection a few times. Also, a few more progress screenshots next tutorial (or video). But thanks, I’m gonna give grids a try!

    @JP – Awesome

  • Pingback: Index.html » Blog Archive » 960 grid system i Axure

  • Gunnar

    I personally like YUI’s grid system, 4 widths by default (of which one is 100% fluid), and I don’t come down with the same amount of divitus with that one.

  • Pingback: 960.gs Grid Based Prototypes › Wireframes Magazine

  • Me

    Reading the comments makes me laugh. I think most of the people choose an opinion just to stand for something and have an opinion.

    These are tools – use the tool that helps you achieve your goal in the “best” (you definition here) way possible.

  • http://www.znshosting.com Ersin Demirtas

    Thank You Adam Hawkins quik brife with Jeffrey Way this article helped me a lot

  • http://mysticpixels.wordpress.com Ranjith

    This indeed is a awesome resource for prototypers and even visual designers. The grid gives the designer a standard to work on and he can make sure that all the designs that are layed out are pretty easy to be converted into logical blocks, which are vital for a prototyper.
    A great contribution to the web developer and designer community…i can say !

  • http://www.hypercas.com HyperCas

    I started with blueprint, using it for a couple of sites. It was easy to pickup and fun. Then it started getting annoying when I had to start overriding a lot of stuff.

    Then I ran across http://www.designinfluences.com/fluid960gs/ and got started using 960. As far as the 960 grid system goes, I really like the margins on both sides of the grid, it feels more right to me…

    Blueprint’s grid generator is really handy when you want to choose your page width and grid size.

    I made a similar one for the 960 grid system, mainly because I wanted to play around with jquery ui system and wanted a different page width for a website I am working on…

    Check it out (made in a really short time)
    http://tool.hypercas.com/960gen/

    At v0.001 it just generates the uncompressed grid css file.

  • Kiribu

    It’s a great solution for 960 site designs. But that’s all it does. People will always try and pull it apart. It’s just another solution for designers who dislike hacks and filters. But it’s got great power, and there’s an advantage to having restraints. Open up Photoshop or Fireworks and design to the grid! Then pop the images into the column divs and serve quickly to the couple on table two. Now that’s what i call a productivity enhancer. It’s called 960. Apologies for the Chef analogy.

  • Pingback: Grid « Catenation’s Blog

  • Aaron Brown

    For all of you who are concerned about corrupting the semantics of your markup, but are still interested in grid frameworks, check out the Compass project. Leveraging Sass, Compass allows one to ‘mixin’ style definitions from various grid frameworks (Blueprint, 960) directly into semantic css class definitions. The upshot being you can have a nav defined as an unordered list possessing the single class “main-nav” and still get the layout benefits of an underlying grid system.

    You can find Compass on github: http://github.com/chriseppstein/compass/tree/master

  • Pingback: Grid Based Design Toolbox | Fuel Your Creativity

  • Pingback: Grid Based Design Toolbox | Coded Ink,Inc

  • http://www.alfystudio.com Ahmad Alfy

    You didn’t take about “prefix_x” and “suffix_x”
    It’s very useful to add before and after your “grid_x” without writing more divs

    Still I find BluePrint Framework closer to my heart!

  • http://tuts.cgbaran.com CgBaran Tuts

    Great Tutorial!!

  • cscsaba

    Hello Guys,

    I need somebody who can explain me why the usage of grid systems represents an effectivness of css framework.

    What are the benefits think in grid systems.

    shred light on the matter, pls .)

    Thanks in advance

    • madmax

      he grid system started with laying out text and graphics for print design, every time you read a magazine, newspaper etc, you are staring at the grid system, you dont realize this because its creates a harmony for you eyes, it also creates a design out of the layout, for instance, you may see a photo in the background of a city, over that photo you see your columns of text in a spot of the photo that contains a large area of one color, then you see a composition of large display fonts creating a design over the photo. this couldnt be done gracefully without css, and now we can use a standard “grid” to “layout” web design instead of hacking and pixel pushing your stuff around until it fits.

      look here, and compare the compositions one is css layout and the other is plain old web.

      http://www.csszengarden.com/?cssfile=150/150.css
      (this looks like a magazine)

      http://oldstylewebdesign.com/
      (this guy is full of crap, he just doesnt know how to use current standards, this site is dookie, remember in back in 2000 when the majority of sites looked like this, everyone needed flash in order to attempt what you can do with lightweight css)

    • madmax

      here is some further explaination,

      http://www.smashingmagazine.com/2007/04/14/designing-with-grid-based-approach/

      in other words, the web will look more and more like interactive web magazines rather than static text.

      Its like the difference between doing magazine layout in microsoft word compared to adobe illustrator or indesign.

      • http://www.communityspiritacupuncture.co.uk aculondon

        wow, is oldstylewebdesign for real? surely a joke?!?

        anyhow, i agree – the 960 grid has allowed me to understand, then create more complex but still visually graceful pages. basically, it makes it easier to bring the knowledge of print (specifically magazine, as you say..) design to the web.

  • Tom

    Thank you, Adam. Excellent tutorial.

  • daidahan

    Hola soy el primer latino que postea, me parece una excelente idea esto de la grilla. SALUDOS DE CHILE

    • anita

      super que alguien hable español

  • Pingback: 100+ Massive CSS Toolbox | tripwire magazine

  • Me

    Use a freakin table for crying out loud!

    • madmax

      OMG, tables? what is the point of furthering web standards, tables give you dookie looking sites with no flexability in layout, css enables all the same directives as print design. you can define how far apart columns of text are down to the very pixel!! you can have total control over how your fonts are styled,

      DUDE tables are lazy!!, save the tables for displaying data from a database, thats what they are for.

  • HesaPesa

    Just don’t get it. The framework systems don’t support standard size banners… Anyone know how to solve it?

  • David

    Create a grid system with the gridsystemgenerator, that way you can define the dimensions and such for the grid and thus fit in standard size banners.

    http://www.gridsystemgenerator.com/

  • CSS Ninjalito

    Seriously. If you haven’t heard of YAML – http://www.yaml.de/en/home.html

    You better check it out. It is the De-Facto of CSS frameworks. Also it is WAY more lightweight. Plus it’s from Germany, you know those Germans are good at stuff.

    Boo yah!

  • http://rathour.com.np/blog Utsav Singh Rathour

    Thanx Just downloaded the layout. Good to find your tutorial