请注意提供的此 clearfix 解决方案 here .
为什么要为 HTML[xmlns] 定义一个单独的样式?
这是针对特定浏览器的 CSS hack 吗?
更新:这是有问题的代码,因为在我看来,有些答案显然离题了。
.clearfix {
display: inline-block;
}
html[xmlns] .clearfix {
display: block;
}
* html .clearfix {
height: 1%;
}
更新 2:它已经或多或少地确定它是一个 hack。但我想要一个详细解释它的外部引用。例如,它适用于哪个浏览器,它究竟要解决什么问题?
最佳答案
我联系了 Stu Nicholls试图追查这个黑客的权威来源。他回复并给了我以下信息:
element[attribute] is a w3.org CSS2 Attribute Selector which is normally applied to body elements and attributes but in this case it uses the tag and its ‘xmlns’ attribute. So [you know it] is to isolate browsers which will either recognise or ignore this style. The answer is that ALL browsers will recognise this style EXCEPT IE5.x and IE6. So all browsers will style the .clearfix as an inline-block, then all but IE5.x and IE6 will restyle this as a block.
Then using the * html prefix to target IE5.x and IE6 ONLY the height of the .clearfix element is set to 1%.
关于css - 为 HTML[xmlns] 定义一个 css 样式是否有一个重要的目的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4604436/