哪些元素“有效”放在标签内?[英]Which elements are “valid” to place inside tag? 本文翻译自  dhblah  查看原文  2012-08-23  16429    html/

时间:2022-11-03 10:16:53

I know that it's not a good idea to place div inside td, but what about span and other elements? Which elements are ok to place inside td and which are not and why?

我知道将div放在td中并不是一个好主意,但是跨度和其他元素呢?哪些元素可以放在td内,哪些不是,为什么?

Edit: The problem is that I have an old table layout and I need to make modifications there. To do so, I need to add elements inside td, so what elements will be the least evil to insert into <td>?

编辑:问题是我有一个旧的表格布局,我需要在那里进行修改。为此,我需要在td中添加元素,那么插入的元素最少是什么?

2 个解决方案

#1


19  

The HTML spec specifies which elements may be direct decendants of other elements.

HTML规范指定哪些元素可能是其他元素的直接后代。

The <td> element has a flow content content model, which means it can contain:

元素有一个流内容内容模型,这意味着它可以包含:

a abbr address area (if it is a descendant of a map element) article aside audio b bdi bdo blockquote br button canvas cite code command datalist del details dfn dialog div dl em embed fieldset figure footer form h1 h2 h3 h4 h5 h6 header hgroup hr i iframe img input ins kbd keygen label map mark math menu meter nav noscript object ol output p pre progress q ruby s samp script section select small span strong style (if the scoped attribute is present) sub sup svg table textarea time u ul var video wbr text

一个abbr地址区域(如果它是地图元素的后代)文章旁边音频b bdi bdo blockquote br button canvas cite code命令datalist del details dfn dialog div dl em embed fieldset figure footer form h1 h2 h3 h4 h5 h6 header hgroup hr我iframe img输入ins kbd keygen标签地图标记数学菜单米导航noscript对象ol输出p预进度q ruby​​ s samp脚本部分选择小跨度强样式(如果scoped属性存在)sub sup svg table textarea time u ul var video wbr文本

#2


4  

The idea that you shouldn't put a div inside a table is more about using semantic markup with CSS to style the layout.

不应该将div放在表中的想法更多的是使用CSS语义标记来设置布局样式。

That being said, <table> and its related elements should be used to display data in a tabular format. If it makes sense for one of the cells in the table to contain more complex markup, then so be it.

话虽这么说,

及其相关元素应该用于以表格格式显示数据。如果表中的一个单元格包含更复杂的标记是有意义的,那么就这样吧。

In the past, <table> was used because it easily gave a website a grid layout, but this should now be done using CSS to allow your site to be more accessible.

在过去,使用

是因为它很容易为网站提供网格布局,但现在应该使用CSS来完成,以使您的网站更易于访问。

#1


19  

The HTML spec specifies which elements may be direct decendants of other elements.

HTML规范指定哪些元素可能是其他元素的直接后代。

The <td> element has a flow content content model, which means it can contain:

元素有一个流内容内容模型,这意味着它可以包含:

a abbr address area (if it is a descendant of a map element) article aside audio b bdi bdo blockquote br button canvas cite code command datalist del details dfn dialog div dl em embed fieldset figure footer form h1 h2 h3 h4 h5 h6 header hgroup hr i iframe img input ins kbd keygen label map mark math menu meter nav noscript object ol output p pre progress q ruby s samp script section select small span strong style (if the scoped attribute is present) sub sup svg table textarea time u ul var video wbr text

一个abbr地址区域(如果它是地图元素的后代)文章旁边音频b bdi bdo blockquote br button canvas cite code命令datalist del details dfn dialog div dl em embed fieldset figure footer form h1 h2 h3 h4 h5 h6 header hgroup hr我iframe img输入ins kbd keygen标签地图标记数学菜单米导航noscript对象ol输出p预进度q ruby​​ s samp脚本部分选择小跨度强样式(如果scoped属性存在)sub sup svg table textarea time u ul var video wbr文本

#2


4  

The idea that you shouldn't put a div inside a table is more about using semantic markup with CSS to style the layout.

不应该将div放在表中的想法更多的是使用CSS语义标记来设置布局样式。

That being said, <table> and its related elements should be used to display data in a tabular format. If it makes sense for one of the cells in the table to contain more complex markup, then so be it.

话虽这么说,

及其相关元素应该用于以表格格式显示数据。如果表中的一个单元格包含更复杂的标记是有意义的,那么就这样吧。

In the past, <table> was used because it easily gave a website a grid layout, but this should now be done using CSS to allow your site to be more accessible.

在过去,使用

是因为它很容易为网站提供网格布局,但现在应该使用CSS来完成,以使您的网站更易于访问。