Learning to adapt to the mobile web
Posted on 23 Apr 2012 at 11:39
Smart web designers need to respond to the mobile web with responsive design, not cut-down pages. Tom Arah explores what's involved
Marcotte’s book shows that there are three main ingredients to such a responsive web design. The first is a fully adaptive dynamic grid and, interestingly, Marcotte starts from a typical Photoshop-created desktop layout that’s been recreated as a fixed, CSS-based grid using pixel sizes.
The trick is to convert fixed pixel dimensions into proportional percentages using the “target/context = result” rule. For example, a 380-pixel column within a 960-wide page container would convert to 380/960, so set “width: 0.3958333333333333%” (without rounding it up). Having sized all the obvious block elements, do the same to margins and padding, and when finished you’ll have a grid that seamlessly adapts to any size of screen – it’s the end of horizontal scroll bars and zoom hell.
With your fully flexible layout sorted, the next ingredient is making the content adaptive, too, and for text this involves a CSS reset, and then setting all font sizes in ems rather than points or pixels. Handling graphics and other embedded media through pixel-independent CSS becomes more complicated: the first obstacle is that, by default, images will display at their native pixel size, and so large images spill out of their containers and look terrible.
With your fully flexible layout sorted, the next ingredient is making the content adaptive
One option is to use “overflow: hidden”, which effectively crops the image to its container, but far more useful is to scale the image to its container using “width: 100%”. However, this can become pixellated if thumbnails and icons are scaled beyond their original pixel dimensions, so most useful of all is the setting “max-width: 100%”, which scales down oversized images to match the width of their container, but doesn’t scale them up beyond their native pixel size.
Intelligent design
We now have a single, universal design based on an adaptive grid and content. However, we still have one major problem, because there’s no such thing as a single universal best layout.
Depending on the shape and size of the final page, a good designer would make entirely different choices on how many images to include, at what size and where, whether to crop them, what fonts, how many columns, you name it. Sadly, one design can’t be made to fit all. It looks like another impasse – but again, that isn’t the case: we just need a mechanism to encompass such individual design decisions within an adaptive page.
This is where the third ingredient of a responsive design comes in. Media queries are a mechanism new to CSS3 that let you inspect the properties of the rendering device and browser, and apply conditional rules. You can query for minimum and maximum widths, as well as for orientation, aspect ratio and density, and you can chain several queries, as in:
@media screen and (min-width: 600px) and
(max-width: 900px) { ... }
Put this all together and you can create hand-tailored break points in your fluid design at which the layout and typography undergo a radical change, such as dropping from a two-column to a one-column grid, hiding certain pictures, swapping navigation bars, changing fonts and so on.
Media queries enable you to build truly intelligent adaptive designs, whose layout and content change radically to best fit the hosting screen.
Is responsive, self-optimising web design really this simple? Sadly not, and Marcotte doesn’t pretend that it is. Most of his book is involved in trying to sort out the numerous problems that crop up, with varying degrees of success.
Tom Arah
Tom is a contributing editor to PC Pro who writes a bimonthly column in the magazine. He specialises in all things design, having set up his Edinburgh-based design company in 1987. As well as design work, he provides training and consultancy.
advertisement
- Start8 and ModernMix: making Windows 8 work on a desktop
- How to boost your mobile reception
- How to fix Facebook: Social Fixer
- Taking the stress out of WordPress updates
- Where to download free web fonts
- Turn your tablet into a Sky+ remote control
- How to measure the success of a new IT system
- Three years on: the state of the tablet market
- Windows 8: what works and what doesn't
- Yes, I write down my passwords
- Flickr redesign: is it enough to tempt photographers back?
- Hands on with the new Google Maps
- Nokia Lumia 925 review: first look
- Why I won't subscribe to Creative Cloud
- GoPro camera strapped to a remote-control helicopter: the ultimate boy's toy
- Acer Iconia A1 review: first look
- Acer Aspire P3 review: first look
- Acer Aspire R7 review: first look
- How we produce the PC Pro podcast
- Google Now draining iPhone battery
- Dell profits slide 79% amid buyout talks
- Forget cloud subscriptions: users prefer standard licences
- McAfee: cloud storage could help spread viruses
- Analysts question Windows 8 as UK PC shipments slump
- Google pools storage across Gmail and Drive
- Ofcom accused of killing off VoIP competition
- ShoreTel dock turns iPhones and iPads into desk phones
- Bill Gates says iPad users "frustrated"
- Intel Silvermont promises three-fold boost for tablets
- Customers fume as BT introduces IP sharing
advertisement
