views:

45

answers:

4

I have external CSS in my project and it contains all the styles for the site, the site works well with FF but gets bad and mad in IE (as-usual).

So, Is there any way to write css such that particular style applies to a particular browser?

If I have a class say:

.col2{ width:237px; }

How can I edit the above class to apply with different width in IE and FF?

NOTE: I DONT NEED JAVASCRIPT TO IDENTIFY THE BROWSER.

+1  A: 

http://www.quirksmode.org/css/condcom.html

Conditional comments are your friend!

If you just need it to work in IE6 you could you the * html 'hack':

define your CSS:

.acol {
width: 100px;
}

then define a style for IE6 to override:

* html .acol {
width: 200px;
}

The second part for IE6 always needs to come AFTER the original declaration

Alex
They say the conditional statements wont work in css files then what should I do? secondly I have to test this in all available versions of IE not only in IE 6
OM The Eternity
You don't put the conditional comments IN a CSS file. In your <head> you have your normal CSS file then you add conditional comments to target an IE-only CSS file.
Alex
And you can use conditional comments to target whichever version you want.
Alex
A: 

The best way is to specify specific css file(s) for IE using conditional comments: http://www.quirksmode.org/css/condcom.html

Another way are CSS hacks but they are messy and usually not welcome (nowadays): http://www.webdevout.net/css-hacks

cherouvim
+5  A: 

I think Paul Irish came up with the most elegant solution: http://paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/

pleunv
Hey, this is quite neat =) +1
David Hedlund
A: 

There is a jQuery plugin called the CSS Browser selector.

You basically put tell the CSS which browser it is for, without the need for conditional comments or anything:

.ie .myDiv 
{background-color: #f00;}

.webkit .myDiv
{background-color: #00f;}

It's really easy to setup and use :)

Kyle Sevenoaks