views:

29

answers:

3

i'm creating a site and i should use different css for different device (pc, ipad, iphone) it is possible to know which device people use to select the css???

+2  A: 

Load different CSS based on the media type:

W3C -Media Types

Justin Niessner
i tried whit <link rel='stylesheet' type='text/css' media='screen' href='style.css'/><link rel='stylesheet' type='text/css' media='handheld' href='style.css'/> but my all pc, mobile and ipod use the screen stylesheet and i suppose also ipad and iphone
Erick
+1  A: 

The best info you have on what platform/device your users are viewing the site on is the browser version, available in the HTTP header. Mobile devices may say they're using Chrome (on an Android phone) or IE (on a Windows Mobile phone), but you should be able to discover from the version information that it's a mobile version of the browser.

You could use JavaScript to dynamically set styles, or a server-side script (ASP, JSP, PHP) to load CSS scripts. What you have to work with depends on what your site is written in. Be aware that making the mobile device run a large JS script to dynamically set styles will not be very performant on a mobile device.

KeithS
+1  A: 

If @Justin Niessner's answer doesn't give enough fine-control, you could try detecting the browser/device from the user agent string. This is frowned upon by some people, and it's not guaranteed to be accurate, but it might be helpful. Basically, detect the browser in Javascript and then dynamically add the correct stylesheet. Alternatively, this could be done server-side.

nickf