用于IE或其他东西的CSS Hack?

max*_*ax7 1 html css html5 css3

请考虑以下CSS规则:

.myClass {
    display: inline-block;
    *
    zoom: 1;
    padding: 12px;
    margin-bottom: 0;
    font-size: 16px;
    line-height: 35px;
    text-align: left;
    *
    background-color: #ccc;
    *
    border: 0;
    border-bottom-color: #eee;
    -webkit-border-radius: 7px;
    -moz-border-radius: 7px;
    border-radius: 7px;
    *
    font-weight: bold;
    font-size: 10px;
}
Run Code Online (Sandbox Code Playgroud)

我意识到星号通常被用作IE的某些版本的黑客,但通常,这种用法以不同的方式出现,如下所示:http://bit.ly/QFRPrQ 我发现有关使用的所有回复CSS中的星号似乎并未解决我在示例中的使用方式.

这只是以特定方式或其他方式使用的IE黑客吗?

Axe*_*xel 5

它被认为是IE的黑客攻击,因为正确呈现CSS的其他浏览器会将星号视为CSS语法错误,并忽略规则中的所有内容.IE忽略星号并继续渲染其余样式.

我强烈建议避免使用此类针对IE的黑客攻击.相反,使用专为具有特定样式的IE定位而设计的CSS条件:

http://www.quirksmode.org/css/condcom.html

<!--[if IE 6]>
Special instructions for IE 6 here
<![endif]-->
Run Code Online (Sandbox Code Playgroud)

  • 更好的方法可能是使用*feature*检测库,而不是尝试定位浏览器细节.其中一个最好的是http://modernizr.com/ (2认同)