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
  • http://www.mjama.com Mohamed Jama

    nice post!

  • Ibrahim Abid

    Great job thanks :)

  • http://www.bhutan-360.com Gelay

    First

    • in the name of many people

      Can’t people just stop commenting like this, gets annoying…

      • drako

        his not even the first…

      • That Guy

        Yes! I’m first.
        I don’t really like these Css frameworks, I prefer to code my own .css files.
        Great tutorial though!

    • http://www.jeba.in Jeba

      Lamest comment on the universe..

    • epox

      you are so stupid!

  • http://www.willmcneilly.com Will McNeilly

    Nice Article, will use this in my next project. Cheers

  • http://blogaites.com Francisco Costa

    Funtastic job… It will save lots of times

  • Scott

    interesting read, 960 grid looks a lot more lightweight compared to blueprint.

    I’d like to take this opportunity to point out that there’s nothing more ridiculous than someone posting a pointless “first” comment when they’re not actually first. *golf clap for Gelay*

  • http://www.netsans.dk/ Morten Brunbjerg Bech

    Also, CSS frameworks generally don’t add much meaning to each element in the front end code.

    Consider the following:


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

    … compared to:


    <div id="header"><a href="images/header.png" alt=""/></div>

    The former doesn’t give you any clues to what the element actually contains, whereas the latter clearly identifies the content of the element.

    • Gavin

      Can you not just rename the class? so change grid_12 to header in both the html and the css? is this possible?

    • http://www.ozzmac.com Moises Urrutia

      That is why you can have both a class and a ID. Then you can use a framework and still know what it is. It saves you time and lets you customize each Div.

    • http://beersurfing.com Elliot

      Create a uniquely named class that doesn’t do anything in your CSS (.empty{}), or just use an ID

    • http://keithratliff.com Keith Ratliff

      I prefer to just add more than one CSS class to the same element.

      Thus:

      Handles both cases.

  • http://james.padolsey.com James

    Thanks for the tutorial Adam. :)

    To be honest though, I really cannot see the benefit of using a CSS framework, it just doesn’t seem worth it to me. I don’t think CSS is sufficiently complicated or involved to deserve any frameworks.

  • http://danielfelton.com Daniel

    great article, although I think its it a bit harsh to criticise it for not being able to scale to 1000px, especially when it’s name is ’960 grid system”

    If you didn’t want a 960px wide page, why use something with 960 in the name?

  • http://www.freshclickmedia.com Shane

    Isn’t this tutorial very similar to this one?

    I agree with James about the benefits of CSS frameworks. Although I understand their place, I don’t like selectors such as grid_5 and grid_12. They’re not particularly semantic. That’s just me :)

  • Tom

    This ridiculous fad of posting “first!” really winds me up. To do it second is somehow even more pathetic. How about a plugin to filter such comments, that’d be a good tutorial!

  • Pingback: AndySowards.com :: Web Development Nerdy Daily Links For 12/01/2008 | AndySowards.com :: Professional Web Design, Development, Programming, Hacks, Downloads, Math and being a Web 2.0 Hipster?

  • http://www.brainythink.com Amt

    nice tut, but i’m using blueprint framework and i see its the better for me now!!

  • http://www.smple.com John

    I started using this grid framework in my design layout and it seems to help with content layout. As far as the CSS though, I still do all of that on my own.

  • http://www.vcarrer.com Vladimir

    @James: The benefit of using CSS Grid Framework is when you have big site with complex grid structure. And the structure changes frequently you don’t want to write CSS for every page. Than you build CSS structure(Framework) who will handle all the pages.If you have small web site with simple grid write your own CSS or use something simple like Malo
    I should probably write tutorial on this subject. There are so much misconception about using or not CSS Framework.

  • Dan

    ^ I feel like CSS only gets so complex. If you’re working on a big site, you should try to keep the varying pages as similarly designed as possible anyway. Look at the tuts sites, for instance. Four distinct tut sites, and they’re all designed the same.

    I feel like it’s more hassle than it’s worth to go in and change all the class and id names in both files to make it semantic. Might as well just take the half hour and start from scratch.

  • http://www.1pixelbrush.com Dan

    First!

    Seriously I agree with Tom, million dollar tut right there.

  • http://iamdanielmarino.com Daniel

    @James: You’re correct in saying that grid_5 and grid_12 as class names aren’t very semantic, but there’s no reason why you can’t specify an id for those divs like “header” or “blog-excerpts” or whatever a suitable id name related to the content would be.

    @Adam (author): you’re use of is unnecessary – part of the beauty of using the 960 grid system is that all of the rows (should) add up to 12 (or 16, depending on the division you’re using), meaning there shouldn’t be any hanging divs that would need to be cleared. If you have content, the next div will automatically go to the next line because of the float.

  • http://iamdanielmarino.com Daniel

    Sorry looks like my use of HTML got removed from my last post… Adam, What I’m referring to is the use of the “clear” class.

  • http://www.danharper.me Dan Harper

    Frameworks are very good for building complicated, heavy grid-based sites (like a newspaper’s site) quickly.

    Personally, I have used 960gs & Blueprint both in production sites and find them great for rapid development. (I prefer 960gs over Blueprint, however).

    It definitely isn’t best practice since you’re using non-semantic tag names, but for what it is, it’s fantastic.

  • http://www.xqlusive.nl xQlusive

    Grids are always very usefull for many things .. Thanx for this extra info about Grids.

  • http://devjargon.com Alex

    Good little overview on grids. I’m a big believer in designing to a grid. I really think it helps maintain a clean look on a website with a large amount of content.

    I’m with Dan and Tom. But until the filtering tut comes along, check this out…
    http://stupidfilter.org/main/

  • http://www.thisisaaronslife.com Aaron Irizarry

    Great read thanks… more grids please!

  • http://blog.insicdesigns.com insic

    960 is really nice css framework. and nive tutorial too.

  • http://broadcastingadam.com Adam Hawkins

    Hey guys! Thanks for the comments on my article.

    From James: “To be honest though, I really cannot see the benefit of using a CSS framework, it just doesn’t seem worth it to me. I don’t think CSS is sufficiently complicated or involved to deserve any frameworks.”

    I agree to an extent. IMO, they have very limited uses.

    From Dan Harper: “great article, although I think its it a bit harsh to criticise it for not being able to scale to 1000px, especially when it’s name is ‘960 grid system”

    If you didn’t want a 960px wide page, why use something with 960 in the name?”

    I was trying to get the point across that it is very structured. If you want to move out of bounds, then you need to change your design strategy.

    • http://far-far-away.com/ Kamrul Hasan

      I am still learning. Yet let us modify it a little. With 12 column-

      If you make the column width 63 instead of 60px you will get,
      12*63+12*2*10= 996 px;

      Again, if width is 64px you will get 1008px.

      Both are closer to 1000 px. what do you say?

      Thanks.

  • moon

    I have a programmer’s background (C, C++, Java, C# now thank God) and had never delved into CSS properly. Frankly, for some stupid reason, I run into a roadblock when working with CSS. I plan on following this tutorial tonight and I can clearly see how it would help a beginner/intermediate like me. Great tut.

  • Daniel Apt

    I’m not familiar with the blueprint framework, so I’ll just stick to the 960 Grid System Framework.

    Well, it works great for fixed width layouts. And a great plus point is that the framework has been tested on several browsers, so the design won’t look all messed up in a different browser *IE cough cough*.

  • http://johnsanders.me John Sanders

    Thanks for the helpful tutorial.

  • M

    I use the 960 GS for all my projects now. It’s really simple to design a website that’s based off a grid, and its super easy to transfer that to the web, because you can see things start to layout really easily.

    Great work.

  • Jarryd

    I can see how CSS frameworks would come in handy for large grid-structured web sites like newspapers and large corporate structures. But otherwise I don’t think I would find a practical use for it.

    Maybe I’m just prejudice from using the YUI Grid CSS combos and not really getting them to work for me. :P

    I could definitely see how this could be handy in many situations, but I think I’ll stick to custom built for now.

  • http://www.craniumdesigns.com Steve

    i don’t like how 960 uses all these extra clearing divs… “”

    i prefer the way blueprint’s css framework does it.

    • http://www.ozzmac.com Moises Urrutia

      You can always hide the overflow of the element in your CSS. Then you will not need to clear it after every row.

  • http://www.fwdir.com Mike rice

    Although I find The Grid 960 CSS Framework very useful, the amount of classes and divs that are used at the same time utterly confuse me.

  • http://patareco.carbonmade.com Patareco

    It’s very important to master CSS, but this particular framework exposed and explained as you did, helped me realize it can save tons of work for these types of layouts with fixed columns.
    Thank you for this post!

  • http://www.wilmingtondesignco.com Gregg Moore

    I have been developing websites for over 10 years now and have flirted with several “CSS Frameworks” (not really a framework, but that’s another article). I consider myself someone who is very knowledgeable when it comes to CSS. I can testify that if you pick one CSS Framework, study it and learn it, you can save yourself hours of throwing a web page or site up. This is extremely important especially when when you average 2-3 sites a week.

    And if you have a team of developers, it is very easy for all of us to jump from site to site in each other footsteps to maintain sites.

    If you only develop a few sites or so a year, CSS Frameworks will not benefit you all that much.

  • toto

    the whole computer world is just a huge mess because of the so many times happening “I’ll dot it better than you”.
    so here is a “is better than” blueprint. but it has nothing to do with it…
    well, one more.

    • madmax

      i dont see what you mean, there is always more than one way to do anything in the computer world. it has nothing to do with “better” its just preference

  • Max

    Mike over @ Capsize Designs combined the best of various CSS frameworks into to one called BlueTrip. I haven’t tried it just yet, but it did get some good feedback.

    I’m all for anything that will speed up my development.

  • http://starpointemarketing.com/blog Ryan

    @DanHarper: I agree, I just started using 960.gs in my designs a few weeks ago (both prototypes and production) and am loving it. Sure, the classes aren’t really semantic, but that doesn’t stop you from adding your own (e.g. class=”grid_6 maincontent” and don’t forget about id=”").

    Another benefit is that it helps you to work within constraints that will make a site easier to manage in the long run, especially if you are working with a team.

    @Steve: have no fear, those clearing divs are completely unnecessary. I’m not sure why he put them in there.

  • Pingback: JeremiahTolbert.com » Blog Archive » links for 2008-12-04

  • Patrick

    The best thing about 960 is it’s grid system, which helps a designer to quickly and easily visualize the page layout. Other than that, I have a big problem with using all of the non-semantic divs, where an ul would be more descriptive.

    It seems to me that these CSS frameworks actually undermine the prototyping process because they prevent the designer from writing proper (X)HTML from the get-go.

    I don’t see a problem with using 960 as visual aid; in fact, I think it’s one of the best grids out there. But after that initial stage, I ditch 960 and write code based on meaning.

  • Nouman Saleem

    Blueprint, from my experience, is far more open in terms of layout and provides a much large selection of sizing.

  • http://resnodesigns.com Bryan P.

    I tend to not understand the purpose the the new “grid” system. In my mind its sending us back to using tables. Maybe I dont fully grasp the beauty of the grid system.

    They just seem like more work and hassle then it should be.

  • Pingback: Del.icio.us op 5 december 2008 | Michel Vuijlsteke's weblog

  • Pingback: Daily Links | AndySowards.com :: Professional Web Design, Development, Programming, Hacks, Downloads, Math and being a Web 2.0 Hipster?

  • Pingback: links for 2008-12-05 at James A. Arconati

  • Pingback: Daily Summary 2008-12-05 - mskari.org

  • Danny M.

    Thanks for introducing me to the 960 Grid. It’s saving me a lot of time in developing a simple website for a client at the moment.

    To comment on Bryan P.’s comment: “I tend to not understand the purpose the the new “grid” system.”

    The grid system is really not new at all. It’s been around for years in print design, usually referred to as the baseline grid, for managing the flow of text.

    From a pure coder’s perspective, I’m sure it makes no sense. However, it’s nice to finally see the grid coming in to more and more CSS discussions on the web, considering that most design-savvy but not-so-techie designers/artists almost always use tables to lay out stuff on their web pages. Google some artist and visit his website, and then check out the code. It’s all just a bunch of table cells. Silly designers, tables are for data!

    • http://www.pulpgirldesigns.com judy

      “Silly designers, tables are for data!”

      ha! that should be on a t-shirt….

  • b_electro

    You’re not a (graphic) designer if you don’t know how to use the grid system. Check out the book, “Making and Breaking the Grid: A Graphic Design Layout Workshop,” by Timothy Samara.

    It’s nice that there’s some overlap between the designer’s layout and the developer’s framework, but really no matter what the technology is or will be going forward, the typographical grid system will be underneath it all, visually holding everything together.

  • kevin7

    Cool! But way to complicated to use…

    • madmax

      its really not once you understand how the classes are to be used in your divs,

      I saw how easy this was the first time i saw it because i had to figure out how to evenly lay out a grid of photos to use with light box and i saw a common pattern in my css, i stumble across this and realize its already written as a system.

  • Jonas

    The point you making about that you have to start over if the client what the layout to be fluid – well you probably get the same problem with your own html and css files too. Even if you build a web site from scratch you will end up with building your own framework for that web site.

  • Martin

    @Morten Brunbjerg Bech: i think its better for prototyping …
    if you had coded the final layout you are able to change the class names ;-) or only adding some semantic classnames beside the grid_3 and so on