Is there a non-trivial purpose for defining a css style for HTML[xmlns]?
Note this clearfix solution offered here.
Why is there a separate style defined for HTML[xmlns]开发者_运维问答?
Is this a CSS hack designed to target a specific browser?
UPDATE: Here is the code in question, since some of the answers are obviously way off the mark in my opinion.
.clearfix {
display: inline-block;
}
html[xmlns] .clearfix {
display: block;
}
* html .clearfix {
height: 1%;
}
UPDATE 2: It's already more-or-less established that it's a hack. But I want an external reference that explains it in detail. e.g., which browser does it apply to, and exactly what problem does it purport to fix?
I contacted Stu Nicholls to try to track down a definitive source on this hack. He replied and gave me the following information:
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%.
It's a hack to set display: block
instead of display: inline-block
for browsers which don't support attribute selectors.
The usual comments about CSS hacks apply — conditional comments are usually a better choice, and if you do use a hack you should include a comment explaining it.
It targets the html tag with the attribute xmlns. It's possible the developer has multiple pages within their site and not all of them contain the xmlns attribute for one reason or another. There is nothing really odd about this code, but the reason for the separation really could only be given by the developer who did it. As I see it, this specification will only impact pages in the site that include that attribute in the html tag.
It is probably a website that contains pages in either HTML or XHTML. XHTML pages will have a namespace (xmlns), so this style will target those pages specifically. I'm not sure if the xmlns attribute is loaded at all in browsers that don't support XHTML. If this attribute is ignored in those browsers, this could also be a trick to apply a different style in those browsers.
Either way, I would call it a trick at most, not a hack.
精彩评论