HTML 表格宽度百分比,表格行平均分隔 [英] HTML Table width in percentage, table rows separated equally
问题描述
当我在html中创建一个表格时,一个宽度为100%的表格,如果我想让所有的单元格(tds)被等分,我是否必须为每个单元格输入宽度%?我有义务"这样做吗?
When I create a table in html, a table with a width of 100%, if I want all the cells (tds) to be divided in equal parts, do I have to enter the width % for each cell? Am I "obliged" to do it?
例如:
<table cellpadding="0" cellspacing="0" width="100%" border="0">
<tr>
<td width="25%"></td>
<td width="25%"></td>
<td width="25%"></td>
<td width="25%"></td>
</tr>
</table>
或者以下也可能是正确的程序,如果我希望每个 tds 平均分配,不要在每个 tds 中写入宽度:
OR the following could also be the right procedure, not to write the width in each tds if I want each of them to be devided equally:
<table cellpadding="0" cellspacing="0" width="100%" border="0">
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
我知道这两种方式都适用,但我只想知道这样做的合法"方式.
I know it works with both manners but I just want to know the "legit" way to do it.
推荐答案
您需要为每个单元格输入宽度 %.但是等等,有一个更好的方法来做到这一点,它叫做 CSS:
You need to enter the width % for each cell. But wait, there's a better way to do that, it's called CSS:
<style>
.equalDivide tr td { width:25%; }
</style>
<table class="equalDivide" cellpadding="0" cellspacing="0" width="100%" border="0">
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
这篇关于HTML 表格宽度百分比,表格行平均分隔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!