Is it possible to add a block of css that I only want to be displayed in Safari and no other browsers?
A:
Using the UserAgent string, you can check for Safari and !Chrome. Both use the WebKit Renderer and both have Safari in the UA string, but Chrome also has 'Chrome'. To be honest, I'd just check for Webkit and code to that because who knows what other WebKit browser put in their UA strings.
Safari :
Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-HK) AppleWebKit/533.18.1 (KHTML, like Gecko) Version/5.0.2 Safari/533.18.5
Chrome :
Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/540.0 (KHTML, like Gecko) Ubuntu/10.10 Chrome/8.1.0.0 Safari/540.0
josh.trow
2010-10-29 16:38:06
The UserAgent string can be spoofed very easily. This is not a reliable approach.
stevelove
2010-10-29 17:12:00
I'm not saying its the best method, but to find SAFARI ONLY is nigh impossible so you take what you can get.
josh.trow
2010-10-29 17:20:36
does css use the useragent to check which browser?
Ascherer
2010-10-29 17:51:25
No, I think you would have to use a JS check in your code and include the appropriate style sheet.
josh.trow
2010-10-29 18:36:26
+1
A:
Here's an example which would set the font colour of your site to green if your browser is safari or opera (both share the common webkit).
@media screen and (-webkit-min-device-pixel-ratio:0) {
body {
color:green; /* Safari only */
}
}
This is taken from another post here
Brian Scott
2010-10-29 17:09:26
I assume you meant Chrome, not Opera. Chrome uses the WebKit engine, Opera uses their own engine (called Presto).
jhurshman
2010-10-29 17:14:07