Anita is My True Love

Google
 

4 June, 2007

CSS Hack:

Filed under: CSS

The Underscore Hack

Let’s start with three simple facts — as Petr Pisar found out.

  1. The underscore (“_”) is allowed in CSS identifiers by the CSS2.1 Specification
  2. Browsers have to ignore unknown CSS properties
  3. MSIE 5+ for Windows ignores the “_” at the beginning of any CSS property name

Therefore, a CSS definition, e. g. _color:red is:

  1. Correct, for CSS 2.1 specification allows it (even if software validators, knowing only older version CSS 2.0, say it’s a bug: they are wrong, it’s correct).
  2. Ignored in any browser but WinIE
  3. Treated as color:red in WinIE

    Thus, this IE’s bug/feature is very simple and clear way to set CSS properties for WinIE only (MacIE doesn’t have this bug/feature). It’s easy to fix e. g. mis-implemented position:fixed in WinIE (see the example).

</p>

<h1>menu {</h1>

<p>position: fixed;

_position: absolute;

}

Same method may be used to fix the min-height property missing in WinIE (see the example 2):
</p>

<h1>box {</h1>

<p>min-height: 300px;

height: auto;
_height: 300px;

}

Note: This uses another WinIE’s bug, treating overflow:visible as height:auto. For details, see the article “The “min-height” Hack”.

I tested it in Windows’ MSIE 5, 5.5, 6, and Opera; Mac OSX’s MSIE 5, Safari, and Camino; and in Mozilla and Firefox.

Comments »

The URI to TrackBack this entry is: http://arnita.blogsome.com/2007/06/04/css-hack/trackback/

No comments yet.

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>



Anti-spam measure: please retype the above text into the box provided.






















Get free blog up and running in minutes with Blogsome
Theme designed by Minz Meyer