为什么为<表>不准里面< P> [英] Why is <table> not allowed inside <p>

查看:539
本文介绍了为什么为<表>不准里面< P>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么不能< P> 嵌套在<表> ?什么是我可以改正?
删除< D​​IV> < P> 标签损坏我的设计。由于网站遵循客户提供的设计。

我有以下的code和它在VS2008中工作得很好,但我得到的警告:

 < D​​IV CLASS =right_articles>
    &所述p为H.;
        <表>
            &所述; TR>
                &所述; TD>
                    < IMG ALT =图未找到SRC =图像/ ribbon.gif的风格=WIDTH:155px;高度:125px; />
                < / TD>
                &所述; TD>
                    < ASP:标签ID =Label1的=服务器文本=标签>< / ASP:标签>< BR />
                    < ASP:标签ID =Label2的=服务器文本=标签>< / ASP:标签>< BR />
                    < ASP:标签ID =LABEL3=服务器文本=标签>< / ASP:标签>
                < / TD>
            < / TR>
        < /表>
    &所述; / P>
    &所述p为H.;&放大器; NBSP;&下; / P>
    &所述p为H.;
        <表>
            &所述; TR>
                &所述; TD>
                    < IMG ALT =图未找到SRC =图像/ medal.gif的风格=WIDTH:155px;高度:125px; />
                < / TD>
                &所述; TD>
                    < ASP:标签ID =Label4=服务器文本=标签>< / ASP:标签>< BR />
                    < ASP:标签ID =Label5=服务器文本=标签>< / ASP:标签>< BR />
                    < ASP:标签ID =Label6=服务器文本=标签>< / ASP:标签>
                < / TD>
            < / TR>
        < /表>
    &所述; / P>
< / DIV>


  

警告1此结束标记没有匹配的开始标记。
  E:\\ WebSite4 \\ test.master 121报警2验证(XHTML 1.0
  过渡性):文本是不允许开合间
  为元素的HTML标记。 E:\\ WebSite4 \\ test.master 5警告3验证
  (XHTML 1.0过渡):元素形式缺少结束标记。
  E:\\ WebSite4 \\ test.master 21警告4类或的CssClass值
  没有定义的。 E:\\ WebSite4 \\ test.master 33警告5文件spacer.gif的
  没找到。 E:\\ WebSite4 \\ test.master 116警告7验证(XHTML
  1.0过渡):元素IMG缺少必需属性ALT。 E:\\ WebSite4 \\ test.master 116警告8验证(XHTML 1.0
  过渡):元素'表'不能嵌套元素'P'之内。
  E:\\ WebSite4 \\ test.master 78警告9验证(XHTML 1.0
  过渡):元素'表'不能嵌套元素'P'之内。
  E:\\ WebSite4 \\ test.master 93



解决方案

在HTML明白的 P 元素不能包含其他块级元素和表格是一个块级元素。在 P 结束标记是可选的,当你试图让一个 P 元素中包含的东西,它不能包含,闭幕 P 标记是由浏览器承担。


  

再pre元素psents一个段落。它不能包含块级
  元件(包括P个本身)。


<一个href=\"http://www.w3.org/TR/html401/struct/text.html#h-9.3.1\">http://www.w3.org/TR/html401/struct/text.html#h-9.3.1

Why can't <p> be nested inside <table>? What is the correction I could make? Removing the <div> and <p> tags corrupt my design. As the website follows a client provided design.

I have the following code and it works fine in VS2008, but i get warnings:

<div class="right_articles">
    <p>
        <table>
            <tr>
                <td>
                    <img alt="Img not found" src="images/ribbon.gif" style="width: 155px; height: 125px;" />
                </td>
                <td>
                    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br />
                    <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label><br />
                    <asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
                </td>
            </tr>
        </table> 
    </p>
    <p>&nbsp;</p>
    <p>
        <table>
            <tr>
                <td>
                    <img alt="Img not found" src="images/medal.gif" style="width: 155px; height: 125px;" />
                </td>
                <td>          
                    <asp:Label ID="Label4" runat="server" Text="Label"></asp:Label><br />
                    <asp:Label ID="Label5" runat="server" Text="Label"></asp:Label><br />
                    <asp:Label ID="Label6" runat="server" Text="Label"></asp:Label>      
                </td>
            </tr>
        </table>
    </p>
</div>

Warning 1 This end tag has no matching start tag. E:\WebSite4\test.master 121 Warning 2 Validation (XHTML 1.0 Transitional): Text is not allowed between the opening and closing tags for element html'. E:\WebSite4\test.master 5 Warning 3 Validation (XHTML 1.0 Transitional): Element 'form' is missing its closing tag. E:\WebSite4\test.master 21 Warning 4 The class or CssClass value is not defined. E:\WebSite4\test.master 33 Warning 5 File 'spacer.gif' was not found. E:\WebSite4\test.master 116 Warning 7 Validation (XHTML 1.0 Transitional): Element 'img' is missing required attribute 'alt'. E:\WebSite4\test.master 116 Warning 8 Validation (XHTML 1.0 Transitional): Element 'table' cannot be nested within element 'p'. E:\WebSite4\test.master 78 Warning 9 Validation (XHTML 1.0 Transitional): Element 'table' cannot be nested within element 'p'. E:\WebSite4\test.master 93

解决方案

In HTML it's important to understand that P elements cannot contain other block level elements and TABLE is a block level element. The P closing tag is optional and when you try to make a P element contain something that it cannot contain, the closing P tag is assumed by the browser.

The P element represents a paragraph. It cannot contain block-level elements (including P itself).

http://www.w3.org/TR/html401/struct/text.html#h-9.3.1

这篇关于为什么为&lt;表&gt;不准里面&LT; P&GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆