css - 为 HTML[xmlns] 定义一个 css 样式是否有一个重要的目的?

标签 css xhtml clearfix

请注意提供的此 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/

相关文章:

第一个表的 CSS

添加 xhtml 时浏览器中的 xml 格式

html - 受 sibling 影响的css clearfix

php - 需要修改 Wordpress 主页模板以包含编辑器字段的忽略内容

html - 当您缩小浏览器时,页眉的背景图片不会占据全宽

css - 使用可滚动 div 剪辑固定/绝对元素

javascript - 如何用html css和javascript用空格编码进度条

utf-8 - 为什么我们在 XHTML 中使用 UTF-8 编码?

java - 如何在 Java 中连接 XHTML 文件以解决任何可能的 CSS 冲突?

html - CSS Clear Float 不适用于媒体查询