blog home

How to apply mobile CSS to smart phone devices

Posted by Jen in coding front-end, trends on December 9th, 2009

screenshot1When I am talking about mobile css, I am looking for safari in iphone, blackberry default browser and this new born but the mobile browser for majority to be - opera mini. These days, in spite of the fact that the third generation phones - smart phones have made the majority share of cell phone market in US, unfortunately the mobile web hasn’t come to a universal standard that we can apply like we do to those modern computer browsers.  As a result, when designing a website for mobile, it usually takes more effort to find a solution to browser compatibility and accessibility. And funnily, most smart phones don’t consider themselves as handheld device, thus this “handheld” media for CSS doesn’t work for them:

<link media=”handheld” href=”mobile.css” type=”text/css” rel=”stylesheet” />


First of all, iphone and its default browser Safari.

Yes, iphone made everything easy for everyone, not just consumers but also iphone application developer as well as web designers :) So this approach is rather simple comparing to all other smart phone devices.

<link media=”only screen and (max-device-width: 480px)” href=”mobile.css” type=”text/css” rel=”stylesheet” />

In order to include all other devices which consider themselves as handheld, we tweak this line to be more general:

<link media=”handheld, only screen and (max-device-width: 480px)” href=”mobile.css” type=”text/css” rel=”stylesheet” />

To be even safer, there are times, the device width is 320 pixel or less. So here we are:

<link media=”handheld, only screen and (max-device-width: 320px)” href=”mobile.css” type=”text/css” rel=”stylesheet” />
<link media=”only screen and (max-device-width: 480px)” href=”mobile.css” type=”text/css” rel=”stylesheet” />

Everything works perfectly well with these two lines, except when you come to W3C CSS validator. Yes, W3C doesn’t recognize the mobile style lines, and it doesn’t let them pass through validation. And there is really nothing you can do about it. for more info, you can see some discussion here: http://csscreator.com/node/28171

Blackberry and its default browser.

Blackberry doesn’t pickup any mobile style sheet no matter what media you set to it, not handheld, not width 480px or 320px. There is only one way to give blackberry a mobile looking page - using javascript and direct the page to a blackberry. Below is the script that works. I also tried to apply some mobile style sheet without directing the page to another, but unfortunately didn’t work. more details hereinafter:

<script type=”text/javascript”>
var deviceBB = “blackberry”;

//Initialize our user agent string to lower case.
var uagent = navigator.userAgent.toLowerCase();
var cssFile = “mobile.css”;
//**************************
// Detects if the current browser is a BlackBerry of some sort.

if (uagent.search(deviceBB) > -1) {
//document.getElementById(’blackb’).href = ‘mobile.css’; // this doesn’t work
window.location = ‘home_bb.html’;

//document.write(’<link href=”‘+cssFile+’” type=”text/css” rel=”stylesheet”>); //this doesn’t work either

}
</script>

Opera Mini

It’s a cool mobile browser, which works well with most smart phones - blackberry, iphone, treo palm, etc. To display your mobile CSS on this browser, all you need is still the two lines:
<link media=”handheld, only screen and (max-device-width: 320px)” href=”mobile.css” type=”text/css” rel=”stylesheet” />
<link media=”only screen and (max-device-width: 480px)” href=”mobile.css” type=”text/css” rel=”stylesheet” />

There is this Opera Mini simulator http://www.opera.com/mini/demo/, which makes it possible to test your mobile styles without a mobile phone, however, it only gives you FALSE result. So don’t use it for testing. Install it to your mobile phone and do the real test from there!

Issues you see in real mobile phones but not in simulator:
Opera Mini doesn’t pick up the font size setting in css. Here is the sentence I got from wikipedia:  Opera Mini supports only one font, which can be set to “Small”, “Medium”, “Large”, or “Extra large” size.

http://en.wikipedia.org/wiki/Opera_Mini

The default setting of font size in mobile phone is “medium”. Be aware of this issue when you design the mobile styles, if you are targeting Opera Mini as your mobile browser - use one font size - medium for all text and let it fit in the page.

Firefox 3.5 and some interesting articles about CSS3

Posted by Jen in coding front-end, trends on August 28th, 2009

ff35Firefox3.5 was released a while ago, yet lazy I just updated my FF today. And the direct reason for that is I read two interesting articles, both talking about some fancy CSS effects to the text - one is about the fancy text gradient/shadow effect, one is about text rotation. Both didn’t work on my FF3.0 or FF2.0. :(

All right, so here we go, FF3.5. How much better is it ? It’s faster, it displays fonts even more nicely, and most of all - it supports CSS3 and above! well, while enjoying this advanced modern browser, I also noticed a few cons - forcing to update the add-ons: I have had the great add-ons of firebug, colorpicker and measurelt, they were working perfect and I had no intention of changing them. But as soon as I installed the FF3.5, it told me I have to update them otherwise they won’t be functioning… anyway, I am not so used to the new interface of firebug yet.

Overall I liked FF from day one. It never lets me down with 2.0, 3.0 and the updated 3.5 version, both as a regular computer/internet user and as a web designer. However, to be a web guy, we need to realize that what we produce is for the mass media, instead of for ourselves. Therefore, the two CSS3 tricks about the text effects are just for fun, but definitely not for real work practice. I am taking notes of those codes, but I would say it’s for the future only, when the market share of IE (of all versions), FF3.0 and below, Safari 3 and below and Opera 9 and below are all close to 0%. When will that happen? You tell me. :)

It’s the twitter time

Posted by Jen in random thoughts, trends on June 21st, 2009

twitterOne thing I have to admit is that I am not an active trend follower, which might not be good for a web designer. So when twitter has become a trend, I didn’t pay much attention to it, until one day I found it’s already everywhere that I can’t even avoid it any more… Yes, it IS everywhere, all TV news, celebrities, everyday enormously growing amount of random people, and even US governments, are all using twitter. It’s not just another social networking website, it is a phenomenon of the generation. It’s quick, short and full of information that you are interested in…. this is exactly what we are for.

Still I am one of millions of the twitter beginners, in the process of finding the value of it while already got addicted to it. Just found some small tricks of usage, and happy to share in here

1. Twitter is associated with many bookmarking website. When you submit a web page to their site, they let you post this site link to twitter meanwhile with just a button clicking.

2. hash (#) is an amazing feature of tagging the keywords. This tag will then be tracked by twitter (after you opt in and follow twitter.com/hashtags) and whenever you post with a tag word (word after #), it will show up as a real time post at http://www.hashtags.org

3. twitter has its simple HTML/JavaScript code that allows you to insert into your own website or other social network site to show your twitter’s updates on those sites.

Want to find out how amazing twitter is? Go experiencing yourself! :)

Leopard now

Posted by Jen in trends on January 6th, 2009

When it comes to daily life stuff, I am not really a fan of chasing the trend to do updates actively. Such attitudes certainly apply to the macbook pro that I’ve been using over the years on an extremely intense basis, I’d say. So when my boss finally requested to upgrade this baby to leopard OS for multiple times, I was as reluctant as I was to clean up my garage with millions of dust covered antiques. yes, my garage has everything, except cars. :P

It all happened within my expectation, problematic and exhausting. I’ve spent 2 full days, to do the very first step of this project - restore the hard drive to an external drive. Having tried USB, firewire and different external drives, different ways, restore from the install disk, restore from the desktop, went to mac forum and even called Apple customer service and being told my warranty is expired, I gave up. Had too much stuff in this baby - not just data, but also the applications which I have no clue how to reinstall since either the CDs are not handy any more or the keys are nowhere to dig out, to take the risk of upgrading without the full disk imaging backup is the last thing I would do.

Days later, I found this software - SuperDuper!, a renowned application for mac restoration. After 2 hours running, it gave me the exact same error message as the Disk Utility in mac says - “Restore failure, input/output error”! Right at the moment I was about to pass out, I found this log file with all my ecstasy. All right, so it turned out to be one of the millions of files in this machine is corrupted - it is the Flash CS3 video encoder. The restore worked perfectly right after I removed this brat.

Now I am with Leopard, will try Time Machine shortly.