I’ve been using 960.gs on a few sites recently. Without wanting to get into a discussion about the pros/cons of using css grid frameworks, I find them useful for some sites.
The 960.gs framework comes with a handy demo that shows a grid overlay, but the GIF images used have no transparency, so it is difficult to add a nice grid overlay to sites when developing them.
On the 960.gs home page there is a button by the thumbnail examples that dynamically adds a grid to the image. I Googled around for a similar solution, but didn’t find one that quite did what I wanted. So, I decided to build a simple jQuery plugin of my own.
Here’s a demo of the plugin in action.
To use the plugin, simply add the following code to your pages for a 12 column grid:
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="js/jquery.960grid-1.0.min.js"></script>
<script type="text/javascript">
$(function() {
$("body").addGrid(12);
});
</script>

Once the plugin is activated, a small toggle link will be visible in the top left-hand corner of the page. Unsurprisingly, if you change the input parameter from 12 to 16, you get a 16 column grid available!
The plugin relies on a couple of PNGs and by default the image path is set to /images/. You can override this setting, along with several others, by passing in some options as follows:
var options= {
img_path: 'img/',
z_index: 999,
opacity:.6
};
$("body").addGrid(12, options);
As well as the image path, it is possible to override the default z-index used by the overlay, in case there is a conflict. You can also alter the opacity of the PNG if you require.
Please feel free to download the plugin for your own use. Let me know of any problems or suggested enhancements.
Tags: CSS, grid, JQuery, linkedin
Many thanks for this great tool! :-)
Great tool, Howie, and thanks for sharing. However, I noticed that when you have a layout with absolutely positioned elements the grids never show up. I’m going to try playing around with the script a bit and I’ll post back here what I find out. :)
The jQuery detection logic you use now checks for a version of jQuery that is no longer the most recent version. So even if I’ve already loaded the latest version of jQuery the bookmarklet still loads v1.4.2.
Perhaps instead of explicitly checking for v1.4.2 you should use feature detection to check for whatever critical feature it is that you need in v1.4.2 and then load jQuery only if that feature doesn’t exist. Since that feature will still exist in later versions it won’t overwrite newer versions of jQuery.
Good point Richard. Gosh, I hardly use this tool as I don’t do much front-end development these days, but clearly others like it. Now that jQuery 1.5 is out I’ll have a rethink.
The tool is only used for development, so loading the extra library on the fly isn’t a biggest crime. The important thing is that it does not conflict with an in place library. Most people developing a site will be using the latest jQuery release. Perhaps I should just use the latest.
Shame that none of the CDN versions are labelled ‘latest’ :-/
Actually, the Google CDN does have a ‘latest’ version. Just use https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js and it will always serve the latest 1.x version. (They haven’t upgraded to 1.5 yet as it was just released the other day…)
How does one extending the grid past the initial page fold? I am on Firefox 4.0.1 (Mac-Intel)
Is it possible to play with the alignment of the grid overlay? For example, shift it x number of pixels to the left or right? It might just be the site I am looking at, but nothing lines up with the grid, including the main content area. If I can shift the grid to align with the content area, then I can at least determine if the elements are out of whack or the whole page is out of whack…
This tool is wonderful.Many thanks for sharing.