There’s been a lot of talk in the intarwebnets recently about the benefits of CSS frameworks. I insist on hand-coding, but I really don’t like working with CSS (particularly haggling with a certain 6th edition browser that starts with Internet and ends with Explorer) so I’ve always like the idea of a structure to make it easy for me, like a GUI framework for desktop apps. I’ve looked into some of the more popular, like Blueprint and YUI, but haven’t liked/used either for whatever reason, though I’ve always liked the concept.
Then, I decided to make this site, and I didn’t use any framework. I started with a pre-made theme and smashed, manhandled, sliced, and diced it until it was something kind of like what I wanted. I had floated div’s, crazy margins, and all manner of other hacks for whipping the stylesheet into submission. I got it working and I wasn’t really with how messy it was, but I didn’t have time to do anything about it with final projects and final exams taking up all of my time. Now that the semester is over, I decided to re-do it.
I decided on 960.gs after reading a blog post about it (wish I could remember where, so I could send some link love). I looked into it and found a professional, well-developed framework that had some good ideas that I was interested in, so I decided to give it a try. Boy am I glad I did. It took only a little more than 2 hours, and it looks better than it did before. Here’s a quick overview of how to use it:
Downloading and Installing
There really is no “installation”. You just download the ZIP file, and extract it into your CSS directory (or your theme’s CSS directory if you’re using Wordpress). Presto! Working framework. I changed the folder paths around a little bit, but you can really use it without changing anything.
The ZIP file comes with a lot of stuff to help you design with the 960 system, including “PDF grid paper, templates for Fireworks, OmniGraffle, Photoshop & Visio, and CSS framework with demo HTML”. I only used the CSS files, which is all you need for coding your site. The system comes with 3 CSS files.
- 960.css – Sets up the grid system, the 12-, and 16-column
containers,alpha,omega, andprefix. This file is necessary to the grid system. - reset.css - “Initializes” the system so that all margins and paddings are 0, outline is 0, etc… This file is necessary to the grid system.
- text.css - Sets the font sizes including headers, adds margins to lists, etc… This file is not technically needed for the system, as far as I can tell.
Also, the CSS files are very lightweight, and won’t add any significant loading time to the page, which is something that other frameworks struggle with.
Using it
The system is based around a 960 pixel-wide grid (hence the name). The grid system is a great way to produce good designs without a lot of overhead (Smashing Magazine’s got a great article about grids). You have the option of dividing the 960 pixels into 12 or 16 columns. 960.gs uses the following classes to structure the page:
container_XXis used in the outermost box to determine how many columns. You can usecontainer_12orcontainer_16.grid_XXis the bread and butter of the system. XX is for how many columns you want the block to be. For example,grid_10will be 10 columns wide. The exact pixel width is determined by how many columns you’ve divided the grid into.prefix_XXallows you to add in blank columns before a block.XXspecifies how many blank columns you want.alphais for if you have children blocks. If you do this, you’ll want the first child to have no margin on the left side.alphamakes that happen.omegais similar toalpha, except that it gives no margin on the right side. Use it for the last child.
That’s it. All you have to do is apply classes to boxes. It’s that simple to use. In the outermost container, decide how many columns to use. Then, all you have to do is add classes to your elements to lay them out on the page. It couldn’t be any easier.
Some gotchas
The padding problem: This isn’t really a problem with the framework. It’s just standard CSS, but it’s good to know. If you want one of your grid_XX cells to have padding, you can’t apply the padding directly to the cell, since that padding will add to the width of the cell, throwing off the grid. The way to pad the grid cells is to add another, non-grid_XX cell inside it and pad that one. The sample code uses <p> for that purpose, but I’ve used <div>. It doesn’t really matter.
The width problem: What if you want your grid to be more or less than 960 pixels wide, or you want it to be fluid? You choose another framework. The framework is named 960 for a reason. It’s 960 pixels wide, and short of hacking the CSS, there’s nothing you can do to change that. However, as detailed on their site, 960 pixels is a great width. From the site:
All modern monitors support at least 1024 × 768 pixel resolution. 960 is divisible by 2, 3, 4, 5, 6, 8, 10, 12, 15, 16, 20, 24, 30, 32, 40, 48, 60, 64, 80, 96, 120, 160, 192, 240, 320 and 480. This makes it a highly flexible base number to work with.
Summary
I’m very impressed by how easy the system is to use, even for a CSS-klutz like me. The class-based layout design makes it extremely easy for me to translate the ideas in my head into CSS code without having to fiddle around with fragile floating and margin-ing.
I haven’t used the system in the most ideal or pure way (see the sidebar in particular), but the overall layout of the site is done totally with 960.gs. It worked perfectly. I didn’t have to hack their files to get it working like I wanted it to. It just worked as advertised, and made me happy.
I didn’t use the other files that came with the package, like the Photoshop template or the PDF paper since I already had the site designed, but I’ve looked at them, and they allow you to design exactly how the page will look, and when you code the site, I’m sure you’ll see it stays true to the design.
Thanks, Nathan Smith, for the great CSS system. You’ve made my life easier, and I appreciate it!
Hey – informative article and I agree, 960gs is great! A quick note: if you want your layout smaller than 960, just pad it with blocks on the left and right and stick your content in a center block
If you want it larger, well then you have some hacking to do. It’d be interesting to devise some “plugins” to 960gs whereby you include them AFTER the base 960.css to allow for different types of layouts. Btw – like your site.
James: Thanks for the comment. You’re right about making it smaller, and I guess if you want it smaller but not by a whole column, you could pad the first and last columns by a certain pixel amount. Great point.
I also like the plugin idea. It could make the system a lot more dynamic and powerful.
Thanks for the thorough write-up. I’m glad that people are finding the grid system beneficial. One nit-pick: I’d say that reset.css isn’t technically necessary, because someone could just do:
*{margin:0;padding:0;}
I just included Meyer’s reset, because it’s a nice way to zero things out, without affecting form elements. But yeah, some sort of resetting should be done, to ensure that there’s no margin or padding from the body, etc.
Nathan: You’re right. The reset file isn’t technically necessary if the user includes their own reset, but if you want to be “pure” and not do any unnecessary layout, they should use that file.
Thanks again for the great framework. I’m using it on some other sites and other projects, and it’s working like a charm.
Update on wanting widths different than 960:
IF you visit http://www.960.gs, there is a big button labeled ‘custom css generator’ which lets you define
1. Number of columns
2. Gutter width
3. EITHER the Column Width OR the Full Width (one is used to determine the other)
And then it spits out custom CSS for you, using the 960.gs method (alpha, omega, grid_x, etc)
I was really hoping to see what push and pull did. From what I read on some other sites, it originally wasn’t there, but it is now. And none of the intro blogs I’ve found mentioned it. An update would be great. I was hoping they’d allow me to do something to the effect of putting the body content first, yet having it display last for SEO purposes.
Adam, have a look at this description.
How do I keep the main content within a 960 grid but have the header and footer expand to the width of the browser (flexible width)?
I guess the trick is to use multiple containers and alter the CSS?
And I noticed that 960 now has a fluid option and am confused about that as well.
@D, place the header and footer outside of a container like so:
…
…
…
And if you want to utilize the grid system within the header:
Have not used that particular fluid option before, but I assume the structure is exactly the same as the standard system with the only difference being that there is no fixed width, that is the layout is completely fluid and will resize to fit the width of the browser.
Ack, there is a html filter, pasted my previous comment here with the relevant HTML: http://stikked.com/view/652851a2
Thanks, Bob! That was very helpful!
Your write up of 960.gs is very helpful to me but as I look at the source code for this page: http://juanpatten.com/2008/working-with-960gs/, I do not see any 960.gs classes such as “grid_12″ and “grid_16″ what happened?
@sze
@sze, i believe “span-xx” is being used instead of “grid_xx” on this page. (see source: span-14, span-10, etc.)
i don’t think it really matters what you call your sections, as long as your pages & stylesheets match and everything’s defined. (ok, now i want to build a site using “hedgehog_xx”. perhaps i will.)