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 t开发者_运维百科he css???
Load different CSS based on the media type:
W3C -Media Types
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.
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.
精彩评论