为什么在浏览器中,html段落标记中的某些文本不属于<p> </p>

时间:2015-06-04 22:06:06

标签: html browser element

请参阅下面的HTML。在浏览器中查看时,最后两个句子超出段落标记,因此会丢失段落的属性。 如果你在文本编辑器中查看html,你会看到所有的verbiage都在段落标签内,但在Firefox和IE浏览器中查看时却看不到。在View Source或Debug控制台中查看源代码。

    <html>
    <head>
    <META http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>TEST</title>
    <meta content="width=device-width" name="viewport">
    <meta charset="ISO-8859-1">
    <meta content="IE=edge" http-equiv="X-UA-Compatible">
    </head>
    <body>
    <div id="page_body">
     <div id="my-content">
      <div id="mymsg" class="mymsgcount">
       <div class="my-menus">
        <div class="my-menutext my-menutext1">
                <h1>This is a test.</h1>
                <p>
                    <content>Determine why the last two sentences in this section falls out of paragraph tag in browswer:<br>
                        <ul>
                            <li>first list item</li>
                            <li>second list item</li>
                            <li>third list item</li>
                        </ul>
                        <br>This is the second last sentence which for some reason falls outside of the paragraph tag when viewed in browser.<br>
                        <strong>Last sentence to fall out of paragraph tag.</strong>
                    </content>
                </p>
        </div>
       </div>
      </div>
     </div>
    </div>
    </body>
    </html>

3 个答案:

答案 0 :(得分:1)

您的HTML结构已损坏。具体而言,如果遇到某些其他元素,<p>元素将自动终止,其中包括<ul>。这意味着无序列表及其之外的所有内容都不是初始段落的一部分。

W3C规范说:

  

如果p元素是立即的,则可以省略p元素的结束标记   接着是地址,文章,旁边,blockquote,div,dl,fieldset,   页脚,窗体,h1,h2,h3,h4,h5,h6,标题,hgroup,hr,main,nav,   ol,p,pre,section,table或ul,element,或者如果没有更多   父元素和父元素中的内容不是a   元件。

您可以将这些项目与<div>组合在一起。

您可以在W3C网站here

上找到相应的具体参考

答案 1 :(得分:0)

试一试......

<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>TEST</title>
<meta content="width=device-width" name="viewport">
<meta charset="ISO-8859-1">
<meta content="IE=edge" http-equiv="X-UA-Compatible">
<style>
p {color:red}
</style>
</head>
<body>
<div id="page_body">
 <div id="my-content">
  <div id="mymsg" class="mymsgcount">
   <div class="my-menus">
    <div class="my-menutext my-menutext1">
            <h1>This is a test.</h1>
            <content>
                <p>Determine why the last two sentences in this section falls out of paragraph tag in browswer:</p><br>
                    <ul>
                        <li>first list item</li>
                        <li>second list item</li>
                        <li>third list item</li>
                    </ul>
                    <p><br>This is the second last sentence which for some reason falls outside of the paragraph tag when viewed in browser.<br>
                    <strong>Last sentence to fall out of paragraph tag.</strong></p>
            </content>
    </div>
   </div>
  </div>
 </div>
</div>
</body>
</html>

答案 2 :(得分:0)

Probalby,因为phrasing content中只允许p-tag,这就是浏览器尝试修复的方式。 也可能是因为<content> - 元素不属于HTML标准。