10 tips for web designers in 2010 – the year of the mobile.
1. Design with a fluid layout, min-width: 320px
There are two factors that make this a necessity. First, mobile device screens are so small that you really need to utilise all of the*available*space. Second,*there are a lot of different screen resolutions out there.*The only way to utilise all of the space available on different sized screens is with a fluid layout.
I have found websites with a minimum width of 320px will look good on most high-end mobile devices like the iPhone, Android and Nokia N97. Here are the screen resolutions of some of the most popular devices:
Device Screen res (height x width)
iPhone 320 x 480
iPhone 4 320 x 480 (scaled by a factor of 2)
Nokia N97 360 x 640
HTC Legend 320 x 480
LG eXpo 480 x 800
Technically, the retina display on the iPhone 4 has a screen resolution of 640 x 960 pixels but don’t worry, if you optimise your site for 320 x 480, the iPhone 4 will scale it up by a factor of two so it fits the whole screen. You will need to insert higher resolution images – but more on that in the next section!
2. Include high res images for the iPhone 4 retina display
The iPhone 4 display has four times the number of pixels as that of the original iPhone. To prevent mobile sites from looking tiny, it magnifies them by 200%. That works great on text and vector images like SVG. But its not so hot on bitmap images (or even the HTML5 canvas so it would seem). To avoid pixelation, you need to insert alternative high resolution images for the iPhone 4.
Designers should create their Photoshop documents with a width of 640 pixels. Developers should export the images at full res for iPhone 4 and 50% res for everything else.
Here’s how to use a CSS media query to insert a high resolution image for iPhone 4:
.myImage {
****height: 40px;
****width: 100px;
****-webkit-background-size: 100px 40px;
****background: url("images/myImage.jpg");
}
@media screen and (-webkit-device-pixel-ratio: 2) {
****.myImage {
********background: url("images/myImage@2x.jpg");
****}
}
The first line that might jump out at you as being a little unusual is probably -webkit-background-size: 100px 40px;. The -webkit-background-size CSS property takes two parameters: width and height. The parameters can be lengths, percentages or "auto", and can even be mixed, i.e. -webkit-background-size: 100% auto. This tells the browser to stretch the background image to a specific size.
The second interesting part is the media query @media screen and (-webkit-device-pixel-ratio: 2) {...}. This means that any styles contained within the curly braces only apply if the device has a pixel ratio of 2 (two physical pixels per measurement pixel). Inside the media query selector, we override the .myImage class, and replace the background image with the high resolution image
myImage@2x.jpg
3. Turn off auto-scaling
Mobile devices will assume your website is optimised for desktop computers unless you tell them otherwise. Add a viewport meta tag to the head section of your HTML to set the width of your website to match the width of the display, render with a zoom level of 100% and prevent the user from zooming in/out.
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
Mobile phones will also adjust text size when the screen orientation changes unless you include a special CSS parameter:
body {
****-webkit-text-size-adjust: none;
}
Bookmarks