Big Stock Photo Promo Code

Big Stock Photo offers nearly 3 million stock photos to choose from - royalty free, starting at $1 per photo. We're able to extend free photo credits to our visitors for a limited time. Click here and use promo code HW2333 when you sign up.

Buy One Domain Name, Get One Free

Looking for a reliable and affordable Domain Name Registrar? Look no further than Dotster. And for a limited time, we're able to offer our visitors a buy one domain name, get one free promotion. Click here to take advantage of this offer.



May 23 2006

CSS Underscore Hack


Filed under:
Tools:

Using the Underscore to Isolate IE Styles

Browsers are not very reliable in their consistency of reading and interpreting styles. Most of the time, this is an annoyance. However, at times it can be used to our advantage. In this case, we will be exploiting Internet Explorer's (IE's) lack of conforming to CSS standards. Standards conforming browsers read only valid CSS (there is no browser that I know of that is 100% standards conforming, although some, such as Mozilla Firefox, come close). So, for example, they would not interpret CSS declarations appended by an underscore:

p { background-color: white; _background-color: black; }

IE, however, goes ahead and skips right over the underscore and proceeds to interpret the declaration. This results in IE's background color changing to black, while it remains white in more standards conforming browsers.

Alternative Solution for IE's Min-Height Problem

In combination with the IE overflow bug, this technique provides one solution for IE's lack of support for the min-height property:

#main { height: auto; min-height: 25em; _height: 25em; }

What it does: This code basically tells IE to adjust the height of #main accordingly, without falling below 400px. Most other browsers recognize the min-height property, which takes care of itself.

Implementing Min-Height with Valid Code

Since the use of the underscore in the methods above is not considered valid style, I am going to provide another method of the above "min-height" hack with valid code:

#main { height: 25em; min-height: 25em; }
html>body #main { height: auto; min-height: 25em; }

How it works: The html>body statement is ignored by IE, which allows the height to be redefined as auto while other browsers rely on the min-height property.

Average: 5 (4 votes)
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • Textual smileys will be replaced with graphical ones.

More information about formatting options

CAPTCHA
This question is used to make sure you are a human visitor and to prevent spam submissions.