Loading different stylesheets for different browsers

A

Andries

I would like my pages to load a specific stylesheet determined by what
browser the pages will be displayed on. I have found scripts to tell
me exactly what browser, version etc. is being used, but I am a bit
confused on exactly what the code should look like to choose the
correct stylesheet file.

Any help?
 
C

Chris Morris

I would like my pages to load a specific stylesheet determined by what
browser the pages will be displayed on. I have found scripts to tell
me exactly what browser, version etc. is being used, but I am a bit
confused on exactly what the code should look like to choose the
correct stylesheet file.

Advice - don't do this. The HTTP User-Agent: header is not mandatory,
and may be incorrect even when it does exist. Depending on the
capabilities of your script, it may even incorrectly detect
identifiable agents such as Opera. Many browsers identify themselves
as something else and you can't tell the difference with the UA
header.

Instead, use the browsers' CSS-parsing capabilities to determine which
CSS they get to render. This way, you only need one stylesheet.

http://www.w3development.de/css/hide_css_from_browsers/
 
T

Toby A Inkster

Sean said:
Here's a question... I want to hide a CSS entry on the HTML tag itself from
IE. Since this is the top of the tree, I don't think child selectors will
work. Any ideas?

Give the HTML a class or ID or some other attribute:

e.g. <html class="foobar">
<html id="foobar">
<html foo="bar">

and then use an attribute selector in the style sheet:

html[class=foobar] { color: red; }
html[id=foobar] { color: red; }
html[foo=bar] { color: red; }

In browsers that understand this syntax (only Opera and Gecko AFAIK), this
will count as more specific than just 'html {...}' in CSS and over-ride
any declarations made there. However, 'html.foobar {...}' and
'html#foobar {...}' are even more specific than that, so will over-ride
'html[class=foobar] {...}' and 'html[id=foobar] {...}'.
 
S

Sean Jorden

Give the HTML a class or ID or some other attribute:


doh! for some reason I was giving <HTML> special status in my mind, it
didn't even occur to me that it could have and id or class. thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top