Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the minus sign or underscore in css do anything?

Tags:

css

This question is similar to the one I asked here. I am cleaning up some files and I came across this in this css:


.something
{
  height: 33px;
  -height: 34px; /* does this do anything?? /
}
and

.something
{
  _width: 150px; / does this do anything?? */
}

EDIT: Okay, so the _ (underscore) is a css hack for IE, which is fine, I'll just leave it, but what about the minus sign, does it do anything at all?

Also, we are not supporting anything below IE 7 anymore, so if anything is a hack for IE6 I can take it out.

like image 481
AllisonC Avatar asked Jun 29 '11 13:06

AllisonC


1 Answers

Straight from the W3C CSS 2.1 Spec -

4.1.2.1 Vendor-specific extensions

In CSS, identifiers may begin with '-' (dash) or '_' (underscore). Keywords and property names beginning with '-' or '_' are reserved for vendor-specific extensions.

However that said, using an underscore to prefix a CSS property is a well known CSS hack to apply that rule for rendering in IE 6.

Since a CSS identifier can start with a '-' (dash) and be valid, this can be used to quickly comment out parts of CSS during development. For example in the CSS below, none of the properties will be set for h1 and only margin will be set for h2.

-h1 { color:blue; margin:2em; }
h2 { -color:pink; margin:2em; } /* property "-color" not valid */
like image 61
Marcel Avatar answered Oct 16 '22 11:10

Marcel