Html 把 <p> 放在 <td> 里面放内容文本好不好?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1944213/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 01:38:38  来源:igfitidea点击:

Is it good to put <p> inside <td> to put content text?

htmlxhtmlw3cweb-standards

提问by Jitendra Vyas

Which is more semantic and valid?

哪个更具语义和有效性?

<td> 
<p>
 content text
</p>
</td>

or

或者

<td> 
 content text
</td>

回答by Asaph

Leave out the <p>tag unless the content of your table cell is trulya paragraph. It's certainly possible to have paragraphs in tabular data, and in that case a semantic <p>would be appropriately placed. But for the common table with data in the cells eg. numbers, names, etc., don't include the <p>.

<p>除非表格单元格的内容确实是一个段落,否则不要使用标签。在表格数据中有段落当然是可能的,在这种情况下,语义<p>将被适当地放置。但是对于单元格中有数据的公共表,例如。数字、名称等,不包括<p>.

回答by netrox

It depends on your intention. If the cell is going to have just ONE paragraph then it makes no sense to add the <p>tag to it.

这取决于你的意图。如果单元格只有一个段落,那么向其中添加<p>标签是没有意义的。

If you intend to have a few paragraphs in the <td>cell then it makes sense to use the <p>tag.

如果您打算在<td>单元格中有几个段落,那么使用<p>标签是有意义的。

回答by WarmWaffles

They are both valid. However, if you are going to have multiple paragraphs, obviously use the <p>tags

它们都是有效的。但是,如果你打算有多个段落,显然使用<p>标签

回答by micahwittman

If the tabular cell data is text:

如果表格单元格数据是文本:

<td> 
 content text
</td>

If the tabular cell data is paragraph(s):

如果表格单元格数据是段落:

<td> 
<p>
 content text
</p>
...
</td>

回答by GrayWizardx

Depends on if you subscribe to the "tables are for tabular data" or the "tables are for layout" school. If you prefer to use your tables for tabular data, and the paragraph is not tabular data the "p" is valid, if tables are for layout, and you have the "p" tag reserved for other layout semantics then its not required.

取决于您是订阅“表格用于表格数据”还是“表格用于布局”学校。如果您更喜欢将表格用于表格数据,并且段落不是表格数据,则“p”是有效的,如果表格用于布局,并且您为其他布局语义保留了“p”标签,则不需要。

Short answer is, its really up to you. :)

简短的回答是,这真的取决于你。:)

回答by kiamlaluno

Both are valid; if that is the only content of <td>, and the content is not being used in JavaScript code, then the second is better.

两者都有效;如果这是 的唯一内容<td>,并且该内容没有在 JavaScript 代码中使用,那么第二个更好。