为什么是<table>不允许在 <p> 内 [英] Why is <table> not allowed inside <p>

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

问题描述

为什么

不能嵌套在

中?我可以做哪些更正?删除

标签破坏了我的设计.由于网站遵循客户提供的设计.

我有以下代码,它在 VS2008 中运行良好,但我收到警告:

<p><表格><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>
</p><p>&nbsp;</p><p><表格><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></p>

<块引用>

警告 1 此结束标记没有匹配的开始标记.E:WebSite4 est.master 121 警告 2 验证 (XHTML 1.0Transitional):开头和结尾之间不允许有文字元素 html' 的标签.E:WebSite4 est.master 5 警告 3 验证(XHTML 1.0 Transitional):元素form"缺少结束标记.E:WebSite4 est.master 21 警告 4 类或 CssClass 值是没有定义的.E:WebSite4 est.master 33 警告 5 文件spacer.gif"没有找到.E:WebSite4 est.master 116 警告 7 验证 (XHTML1.0 过渡):元素 'img' 缺少必需的属性 'alt'.E:WebSite4 est.master 116 警告 8 验证 (XHTML 1.0Transitional):元素table"不能嵌套在元素p"中.E:WebSite4 est.master 78 警告 9 验证 (XHTML 1.0Transitional):元素table"不能嵌套在元素p"中.E:WebSite4 est.master 93

解决方案

在 HTML 中,理解 P 元素 不能包含其他块级元素,TABLE 是块级元素.P 结束标签是可选的,当你试图让 P 元素包含它不能包含的东西时,结束 P 标签被假定为浏览器.

<块引用>

P 元素代表一个段落.它不能包含块级元素(包括 P 本身).

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 est.master 121 Warning 2 Validation (XHTML 1.0 Transitional): Text is not allowed between the opening and closing tags for element html'. E:WebSite4 est.master 5 Warning 3 Validation (XHTML 1.0 Transitional): Element 'form' is missing its closing tag. E:WebSite4 est.master 21 Warning 4 The class or CssClass value is not defined. E:WebSite4 est.master 33 Warning 5 File 'spacer.gif' was not found. E:WebSite4 est.master 116 Warning 7 Validation (XHTML 1.0 Transitional): Element 'img' is missing required attribute 'alt'. E:WebSite4 est.master 116 Warning 8 Validation (XHTML 1.0 Transitional): Element 'table' cannot be nested within element 'p'. E:WebSite4 est.master 78 Warning 9 Validation (XHTML 1.0 Transitional): Element 'table' cannot be nested within element 'p'. E:WebSite4 est.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;table&gt;不允许在 &lt;p&gt; 内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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