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

霸气de小男生 提交于 2019-11-30 00:57:40

问题


Which is more semantic and valid?

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

or

<td> 
 content text
</td>

回答1:


Leave out the <p> tag unless the content of your table cell is truly a 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>.




回答2:


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.

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




回答3:


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




回答4:


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>



回答5:


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.




回答6:


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.

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



来源:https://stackoverflow.com/questions/1944213/is-it-good-to-put-p-inside-td-to-put-content-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!