Was working with cool co-worker Chris Sexton about how to solve a problem we'd been having at work. That problem was trying to keep our site mobile-friendly, but not have to spend time designing for it, or doing special CSS.
The First Problem...
IThe first problem we worked through involved how to adjust the page's real HTML width on the fly depending on who was looking at it. In addition, we wanted to make the devices 'viewport's be full. So - if I had a mobile browser with a width of 350px and one with a width of 380px, it would always fill the entire screen. Chris wrote up a cool explanation of the mechanics behind how we do it.
With that code, we can have the viewport adjust to preset sizes, which are aligned with preset sizes in our media screen CSS rules. It works like magic! Each device 'class' has a defined screen size which fills their display. And it's just so awesome.
But... Why?
So I wanted to get into a bit about why we decided to do things this way, and what it really leverages. What it really buys you.
Our layout is a standard 3 column layout like this:
We need a standard way to adjust things, at the column level, in order to make it magical. We want to abide by a few design rules, and then it all just 'works'.
On our site, the right side is just ads, the left side is a set of filters / controls, and the center is the content. The content is about 485px wide.
Our rules ended up being:
- Tablet view just drops the right column
- Mobile view drops the right column and then stacks the left column on top of the center one (expanding it a bit with CSS)
- Modals MUST always be the same width as the center column.
Now our modals are also a bit special, in that they are real pages, with only center column content, which are loaded into the page with JS. Very cool from a code perspective, since the JS is unnecessary, but it has really given structure to our site and consistency to what we do. It also lets us do things like this.
Since the modals are never wider than the center column, they work on mobile just as well as on tablet and main site views.
For the mobile view we ended up having to do a bit of CSS for the headers. And we also used CSS :before tags to inject some anchors into the page. Those anchors let us hide and show the filters with jQuery.
All in all - it's a really cool architecture, and as long as we stay within the rules we've set out, everything just 'works' so wonderfully....
We'll see how long the beauty lasts before a new requirement musses with us....
But until then... enjoying the design. :)