You are here

Differentiating CSS for IE7 IE6 and firefox

if you put # before any css tag, only IE 7 and IE 6 will read that line.
if you put _ before any css tag, only IE 6 will read that line.

example:

width: 560px;     /* All other browsers */ 
#width: 558px;    /* IE 6 & 7 */
_width: 557px;    /* IE 6 */

just remember to keep this order.

Comments

Hi Nima,
I am 25 year veteran DOS and Windows programmer and am just now learning XHTML/CSS to create a web site.

This method seems to work in these 3 major browsers and assume it will not kill any others.

When I submit it to the W3 CSS Validator it complains. A sample:
html {
font-size: 12px; /* Firefox+ */
#font-size: 75%; /* IE6, IE7 */
_font-size: 100%; /* IE6 only */
font-weight: normal;
}

W3C CSS Validator Results for file://localhost/TextArea
Sorry! We found the following errors
URI : file://localhost/TextArea
3 html Parse Error - .font-size: 75%;
6 Parse Error - : 100%; font-weight: normal; }

I also found a similar suggestion using a period instead of pound sign but it also fails.

Using the !important validates but doesn't give as much control.

Is this something we will have to live with?

Thanks
Tom
(:-{>

Hi Tom.
Actually this trick, !important, period and ... are not valid structures for CSS.
Since I rarely need to use this trick in my style sheets, I ignore any validation error about that.

Regards.
Nima

css Font examples , Properties , Attribute - - //
http://www.css-lessons.ucoz.com/font-css-examples.htm

Nima, thank you for posting this amazing tip. Like you mentioned, CSS (Cascading Style Sheets) are very powerful and do have many advantages over plain HTML coding. The trouble is finding all of these powerful gems of information that make a website work in all browsers like we want them too. The big sites that go over the CSS syntax and commands are very good but tend to fail when it comes to the information that you provided in this post. I thank you kindly for sharing this tip as well as the proper layout or syntax.