开发者

H2 tag magically appearing

I have this .html file with just these contents:

<html><body><div class="main_text">
<h2>H2 text<h2/>
<p class="normal">
Look ma no h2 tag darnit!
</p>
</div></body></html>

When I open that file in Safari, the Look ma no h2 tag darnit! part looks pretty big. I get suspicious. So view source, and I get

<html><body><div class="main_text">
<h2>H2 text<h2/>
<p class="normal">
Look ma no h2 tag darnit!
</p>
</div></body></html>

So it's just the same as the above.

Go to Develop -> Show Web Inspector, right click on <html>, select Edit as HTML, copy and paste and I get:

<html><head></head><body><div class="main_text">
<h2>H2 text</h2><h2>
<p class="normal">
Look ma no h2 tag darnit!
</p>
</h2></div></body></html>

Whoa! Where d开发者_开发问答id that extra h2 tag come from??? What am I doing wrong here?

And just in case you were wondering, if I edit out the h2 stuff in the web inspector, the page displays as I intended it to.


<h2>H2 text<h2/> should be <h2>H2 text</h2>. The browser is trying to recover from you having two start tags and no end tags.


Your first closing tag is actually <h2/>, not </h2>. The browser is implicitly closing the first <h2>, and with its flexible interpretation of malformed html, starting a new one based on the improperly self-closed <h2/> thereafter. It's making a logical guess as to where this new second <h2> should be closed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜