css中的减号或下划线有什么作用吗? [英] Does the minus sign or underscore in css do anything?

查看:181
本文介绍了css中的减号或下划线有什么作用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题类似于我在这里提出的问题。我正在清理一些文件,我在这个css中遇到这个:

  
.something
{
height:33px;
-height:34px; / *这做什么? * /
}



  
.something
{
_width:150px; / *这做什么? * /
}



编辑:是一个css hack的IE,这是好的,我只是离开它,但是减号,什么做任何事情呢?



此外,我们不再支持IE 7以下的任何东西,所以如果任何东西是IE6的黑客,我可以拿出来。

解决方案

直接从 W3C CSS 2.1规范 -


4.1.2.1供应商特定的扩展 / p>

在CSS中,标识符可以以' - '(dash)或' / code>'(下划线)。关键字
和以' - '或' _ 开头的属性名称保留给供应商特定的扩展。


但是,使用下划线作为CSS属性的前缀是知名的CSS hack 来应用该规则在IE 6中渲染。



由于CSS标识符可以从a' - '(dash)并且有效,这可以用来在开发期间快速注释掉CSS的一部分。例如在下面的CSS中,不会为<$​​ c $ c> h1 设置任何属性,只有 margin code> h2 。

  -h1 {color:blue; margin:2em; } 
h2 {-color:pink; margin:2em; } / * property-color无效* /


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.

解决方案

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 */

这篇关于css中的减号或下划线有什么作用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆