Razor
Razor

Reputation: 17498

Including style sheets for different browsers without JavaScript

I have a utility that scans through my css file and embeds images as base64 to reduce the amount of requests made to the server. Unfortunatly, IE does not support this.

I know how to include IE specific style sheets using conditional comments, but what about FF, Opera and Webkit? I don't want to give IE style sheets that it doesn't use.

Thanks

Upvotes: 1

Views: 681

Answers (5)

j.j.
j.j.

Reputation: 2100

Instead.The best way to do is using the following. type="text/safari" type="text/chrome"

Nooo, don't rely on browser bugs! Chrome plans to fix this (and therefore disabling this hack) in version 50.

http://code.google.com/p/chromium/issues/detail?id=286682

https://groups.google.com/a/chromium.org/forum/m/#!topic/blink-dev/nH1O6WszMgo

Upvotes: 0

An Object
An Object

Reputation: 309

Instead.The best way to do is using the following.

type="text/safari"

type="text/chrome"

read the following post for better explaination.

http://webgyani.com/2010/03/how-to-serve-different-stylesheets-only-to-safari-and-chrome/

-Amit

Upvotes: 0

Johannes Gorset
Johannes Gorset

Reputation: 8785

There are no conditional comments for Firefox, Opera and Safari. I'm unsure whether you may load stylesheets with Javascript, but I would recommend against it either way.

It's common to have a server-side scripting language like PHP determine the client and serve corresponding CSS files. In PHP, the user agent may be identified by parsing the contents of $_SERVER['HTTP_USER_AGENT'].

If you're not comfortable with programming in PHP, there are a number of scripts that you could use. This one seems particularly promising.

Upvotes: 2

SLaks
SLaks

Reputation: 887285

If I understand your question correctly, (and if I don't), you can exclude CSS files from IE using conditional comments:

<![if IE 9]>
IE will ignore this; other browsers won't.
<![endif]>

Upvotes: 2

Jon Winstanley
Jon Winstanley

Reputation: 23311

By reading the user-agent in the web request, you could serve up a different style sheet in your HEAD tags.

Upvotes: 0

Related Questions