Different CSS for iPhone and other portable devices
With Apple’s iPhone and iPod Touch, Google’s Android smartphones and other portable devices gradually dominating the market, it is getting more important to optimize websites to look better in these relatively-smaller-screen portable devices.
If you have been in CSS game for quite a while, you may think that defining media=handheld will do the trick
@media handheld {
.navigation {
display: none;
}
}
Unfortunately Apple defined it in such that iPhones will look for “screen” media type instead of the limited “handheld” media which deem to be outdated.
The solution to this is to specify CSS rule that looks at the device screen resolution.
There are some sayings that Internet Explorer has issues ignoring the CSS rule, but that can be easily fixed with Internet Explorer’s “conditional comments” feature.
Conceptually, you can define a separate set of CSS for iPhone (or devices with width less than 480px) as follow:
<!--[if !IE]>-->
<link media="only screen and (max-device-width: 480px)" rel="stylesheet" type="text/css" href="iphone.css"/>
<!--<![endif]-->
And the iphone.css can be any CSS definitions that will overwrites the original CSS definitions.
Hopefully this basic and simple trick can help you to kick start your website revamp to cater for different sizes of portable devices.
Got anything to say? Go ahead and leave a comment!
Archives
- May 2012
- March 2012
- February 2012
- July 2011
- June 2011
- May 2011
- February 2011
- January 2011
- December 2010
- November 2010
- October 2010
- September 2010
- August 2010
- July 2010
- June 2010
- March 2010
- February 2010
- January 2010
- December 2009
- September 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008



Posted under: