简体   繁体   English

无法在Firefox和Chrome中正确解析HTML

[英]HTML not correctly parsed in Firefox and Chrome

With this snippet of HTML, the topmost google link is included in every element under it when shown in Firefox and Chrome. 使用此HTML代码段,当在Firefox和Chrome中显示时,其下方的每个元素中都包含最高的google链接。

 <div>
    <a href="http://www.google.com/">
        <div>
            <div>                     
                <div>
                    <div>
                        <a>a tag</a>
                    </div>
                    <img />        
                    <h3>a title</h3>
                    <p>a description</p>
                    <div>a detail</div>
                </div>
            </div>
        </div>
    </a>
</div>

在此处输入图片说明

What is causing this parsing issue and how can I fix it? 是什么导致此解析问题,我该如何解决?

Try dropping the following document into the W3C Validator : 尝试将以下文档放入W3C验证程序

<!DOCTYPE html>
<html>
    <head>
        <title>Parse error?</title>
    </head>
    <body>
        <div class="g23">
            <a href="http://www.google.com/">
                <div class="article-bg">
                    <div class="splash-border-right">                     
                        <div class="splash-content-margin">
                            <div>
                                <a href="http://www.google.com/">a tag</a>
                            </div>
                            <img src="http://www.google.com/image.jpg" />        
                            <h3 class="splash">a title</h3>
                            <p>a description.</p>
                            <div class="read-time">a min</div>
                        </div>
                    </div>
                </div>
            </a>
        </div>
    </body>
</html>

Observe that this document is not valid HTML5. 请注意,该文档不是有效的HTML5。 The first error: 第一个错误:

Line 13, Column 65: An a start tag seen but an element of the same type was already open. 第13行,第65列:看到了一个开始标记,但是相同类型的元素已经打开。

That is, a tags must not include other a tags. 也就是说, a标签不得包含其他a标签。 According to Alohci in the comments, Chrome and Firefox's behavior matches the HTML5 spec's adoption agency algorithm for this scenario. 根据Alohci的评论,Chrome和Firefox在这种情况下的行为符合HTML5规范的采用代理算法 It's funky, but, with invalid code, funky results are to be expected. 它很时髦,但是使用无效的代码,可以期望得到时髦的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM