更新:这里是a follow up question with colspans。删除多列后的相同单元格宽度
我有一张8列的表。在运行时,任意数量的这些元素都被删除。
其余的列将具有相等的宽度。问题在于元素内部的文本有不同的宽度。因为浏览器似乎根据每个单元格内文本的长度来设置单元格宽度。 OK,这个形象可能会更好说它:
这里是代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
table{
width:600px;
}
table td{
border:1px solid red;
text-align:center;
background-color:#FFFFCC;
}
caption{
color:blue;
font-size:80%;
}
</style>
<title></title>
</head>
<body>
<table>
<caption>Original table</caption>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
<tr>
</table>
<table>
<caption>After some columns are removed</caption>
<tr>
<td>1</td>
<td>2</td>
<td>4</td>
<td>5</td>
<td>7</td>
<td>8</td>
<tr>
</table>
<table>
<caption>I want these to have the same width</caption>
<tr>
<td>1</td>
<td>Two</td>
<td>Three</td>
<td>Column number four</td>
<td>5</td>
<tr>
</table>
<table>
<caption>I want these to have the same width, too</caption>
<tr>
<td>1</td>
<td>Column number four</td>
<td>5</td>
<tr>
</table>
</body>
</html>
我搜索计算器,发现下面的职位,但他们不是我的答案:
- Creating columns of equal width
- How do you make a 100% width table with the columns all equal width?
难道你不能将表格布局设置为固定,然后通过将每个宽度设置为总宽度除以单元格数量来调整单元格大小? – j08691 2012-02-02 16:26:37