td 标签外的标签未显示在表内 [英] Tags outside td tags not displayed inside the table

查看:30
本文介绍了td 标签外的标签未显示在表内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很困惑为什么这里没有插入 br 标签,即使我把它放在 tr 标签中.

I'm confused as to why br tag is not inserted here, even if i put it inside a tr tag.

HTML:

<table border=1>
    <tr><td>1</td></tr>
    <br/>
    <tr><td>2</td></tr>
    <tr><td>3</td></tr>
</table>

表格前的空白区域(即 br)是输出:

An empty space(which is the br) before the table was the output:

Empty Space
1
2
3

我已经发现通过将它放在 td 标签中是可能的,但我仍然很好奇为什么没有 td 就不能完成它标签.

I already figured out that it;s possible by putting it inside a td tag but I'm still curious on why it can't be done without the td tags.

提前致谢!:)

推荐答案

<br/> 元素在给定位置无效,因为 HTML 语法不允许 之间的任何内容tr 元素但其他 tr 元素(以及,在 HTML5 中,script 元素).当遇到这种无效标记时,传统的浏览器行为是将其视为出现在 table 元素之前.此错误处理在 HTML5 中标准化,位于 意外标记部分在表格中.

The <br/> element is invalid in the given position, since HTML syntax does not allow anything between tr elements but other tr elements (and, in HTML5, script elements). When such invalid markup is encountered, the traditional browser behavior is to treat it as if it appeared before the table element. This error processing is being standardized in HTML5, in section Unexpected markup in tables.

与此无关,仅使用 br 元素来创建垂直间距是粗糙且不可靠的;在 HTML5 中,它被声明为无效(有点模糊,请参阅 br 元素).在 td 元素的末尾使用 br 通常会在那里创建一个空行,但这可以通过在元素上设置 padding-bottom 来更好地实现在 CSS 中.

Independently of this, using the br element just to create vertical spacing is coarse and unreliable; in HTML5, it is being declared as invalid (somewhat obscurely, see the current description of the br element). Using br at the end of a td element typically creates an empty line there, but this is better achieved by setting padding-bottom on the element in CSS.

这篇关于td 标签外的标签未显示在表内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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