html <h3> tag in <dt> tag

落花浮王杯 提交于 2019-12-25 02:32:55

问题


I've noticed an awkward occurence in Firefox/Firebug:

<dl>
    <dt><h3>test</h3></dt>
    <dd>stuff</dd>
</dl>

renders as this

<dl>
    <dt></dt>
    <h3>test</h3>
    <dd>stuff</dd>
</dl>

I've never seen this happen before. Can anyone explain why?


回答1:


Probably because it's invalid XHTML and this is how the Firefox's error recovery works:

Line 14, Column 12: document type does not allow element "h3" here; missing one of "object", "ins", "del", "map", "button" start-tag

http://validator.w3.org

FWIW, I tested Chrome, IE and Opera and none of them exhibited the same behavior. This is a solid argument for why you should write valid markup and not rely on the parser's error recovery - browsers handle errors in their own way.




回答2:


Yeah. <dt>s can't contain <h3>s according to the DTD.

Firebug doesn't show you your actual source; it shows you what Firefox rewrote your source to before rendering. Firefox, like every browser, will make guesses about what you meant when you write invalid markup. What you're seeing is the result of that guess.

The solution going forward, of course, is to write standard code.



来源:https://stackoverflow.com/questions/3546327/html-h3-tag-in-dt-tag

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!