Media Queries and Handheld stylesheets
Sunday, 17. June 2007, 22:40:24
When designing for mobile, one has a few options. These include doing nothing and relying on how the mobile browser reformats the page (using either small screen rendering, desktop view or both depending on the browser), creating a new mobile friendly site, or restyling the page using handheld stylesheets or Media Queries. I'll look at the latter two here.
As part of the preparations for the Opera Mini 4 launch this Tuesday, I've been developing our developer documentation. This includes examples of using both handheld stylesheets and CSS3 Media Queries. The first example uses Media Queries to reformat the page when the screen is 480px wide or smaller. The code could be optimised more, and the design is simple so small screen rendering on its own would probably do a good job, but it is an example of what can be done. On a more complex page with images the results would be more worthwhile. Both screen and handheld were specified as the S60 browser from Nokia and the Safari iPhone browsers both ignore handheld stylesheets, so the screen media type had to be specified for those browsers. I choose 480px for the width as that is the resolution of the iPhone when in landscape mode, but any width could have been chosen. max-device-width doesn't have to be used, I could have chosen max-width, or any other number of options. I don't have a S60 or iPhone browser to test, but I suspect they will both render similarly to Safari 3, minus the font differences. Opera Kestrel and above have improved Media Query support so that the changes kick in without refreshing the page. This means in the previous example it will apply the Media Query content as soon as the browser view port is 320 pixels wide. As you could imagine, once more browsers support this, it would be very useful for elastic layouts to stop content overlapping when the browser window gets too small. The contents could be set to clear instead for example.
The second example is based on the first and and uses handheld stylesheets. It sets the stylesheet in the above example to only apply to the screen media type and creates a new stylesheet with the handheld media type. This means that browsers that support handheld correctly will only apply the second stylesheet. This stylesheet then includes all the styles needed to create the design.
As can be seen in these two fairly simple examples, it is possible to optimise for mobile without too much difficulty, or learning many new techniques, as long as your mark-up is clean and without presentational aspects, such as tables for layout. Unfortunately, handheld support is not where it could be, but Media Queries are well supported in modern full HTML mobile browsers. If your web sites page will benefit from it, I'd recommend you give Media Queries a try. I'd recommend specifying in the stylesheet that images and any content have a max-width of under 100% so that horizontal scrolling is not needed.
Adding hundreds of links to other articles, forum threads, and what not on every page before/over the article the user came there to read will drive him away in the long run. With your* simple solution, the web designer doesn't have to chose between adding those links or making the user happy.
Though, when I think about it again, I would still argue that it is better for the consumer to be presented with:
- Basic navigation, then->
- The article/picture/tutorial/video he was looking for, then->
- Additional navigation (internal/external links).
It will feel like a more natural flow, since he came to that page in the first place to read the article, and after that he will chose again where to go next. In this way he doesn't have to scroll to scroll back up again after reading, or getting distracted on the way down finding an other more interesting link.
Without pointing at this page in particular (since I really love the content here), I hope I don't offend anyone by using them as an example. Try to look at this article with images turned off** in Opera Mini. Are you too having a hard time finding the start of that article?
*Not sure if that "trick" is already widespread, or if it was something you just made up.
**You turn off images by clicking: Menu->Tools->Settings, and uncheck "Load Images". Then press save. You need to reload the page again for the changes to take effect: Menu->Tools->Reload.
PS: Sorry, for ending up ranting in your comment section, when all I wanted to do was to compliment you on your efforts. Looking forward to Tuesday.
- ØØ -
By NoteMe, # 18. June 2007, 00:23:46
By dstorey, # 18. June 2007, 11:09:27
Very nice to see this fixed, it has annoyed me for some time now
By Daedalus, # 18. June 2007, 16:06:58
Note that some mobile browsers do not care about media types at all (IEMobile and NetFront).
I wrote about this in http://johannburkard.de/blablog/www/mobile/2007/06/14/NetFront-and-handheld-CSS.html and http://johannburkard.de/blablog/www/mobile/2006/05/23/Linking-CSS-for-handheld-devices.html.
By anonymous user, # 18. June 2007, 20:32:48