Developing responsive websites with the Skeleton media query framework
comments (11) Views: 8,157
Responsive web design is all the rage right now. It's a buzz word that means a website that adjust itself to the users environment: whether mobile, or desktop; large screen or small. But it's also more than just the mechanics of building a site, it's also the conceptial phases, and the approach to developing the assets. It's become fairly easy to build media query based sites, as evidenced by the excellent mediaqueri.es gallery. One way of building these responsive sites is the excellent Skeleton framework written by Dave Gamache, a designer at Twitter.
The Skeleton framework, at it's core, is a collection of CSS and HTML files which combine to make a website that can be adjusted to 4 distinct sizes. There's full size (960px and above), tablet portrait (768px to 959px), mobile landscape (480px to 767px), and finally mobile portrait ( 300px to 479px). Additionally Skeleton bases it's layout on the 960 grid system. This provides styles that easily allow content columns to sized from full width down to a single column, and any combination in between. Want a 2 column site? Done. 3 column? Done. 4 column? Done! Skeleton has all of that built in, and more.
Skeleton's magic is comprised of three files:
- base.css - this file acts as a sort of reset, zeroing out all browser inconsistencies and providing a level surface to code upon. It also provides beautiful defaults for buttons, links, form elements, and headings. You probably won't need to change this file very often.
- skeleton.css - the core structural file. It contains declarations for all column definitions. It's mostly widths, margins, and padding. You probably won't have to change this file much either.
- layout.css - This file is an empty canvas, waiting for the paintbrush if the master, you! This is where you'll put your site-specific styles. The file is well laid out with clearly defined sections to make organizing your CSS simple and efficient. If you do decide to change something from one of the other two files, it's a best practice to simply override the style in this file.
Open up layout.css and efficiency stares you in the face. There's a copyright notice and a table of contents. Skipping past those you see sections for Site Styles, Page Styles, and Media Queries. The first two are empty, waiting for you to fill them. The Media Queries section contains 5 empty declarations which allow the site to be responsive. I took the liberty of narrowing those down to 4 after a little examination. Let's examine those closer:
@media tells the browser a media query is coming. Screen tells the browser that this is only for visual display (not print). Then comes the actual query...it's simply a CSS definition. You recognize that don't you? Here they check for max-width, but they could just as easily check for orientation, resolution, and other good stuff. In addition to having all of your code inside one master CSS file, you could just as easily split them out so the browser only needs to download the files it can understand. You do that like so:
I hope this short overview is the catalyst for trying out Skeleton and building a media query site of your own. I converted an existing Flash site into a media query based HTML 5 site in just under 10 hours using Skeleton. I guarantee you that it would have taken far longer without it. Good luck.
If this article was interesting, or helpful, or even wrong, please consider leaving a comment, or buying something from my wishlist. It's appreciated!