【发布时间】:2012-02-02 16:22:52
【问题描述】:
更新:这里是a follow up question with colspans。
我有一个有 8 列的表。在运行时,任意数量的这些元素都会被移除。
其余列的宽度相同。问题是当元素内的文本具有不同的宽度时。因为浏览器似乎根据每个单元格内的文本长度设置单元格宽度。好的,这张图片可能说得更好:
这里是代码:
<!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>
我搜索了stackoverflow并找到了以下帖子,但它们不是我的答案:
【问题讨论】:
-
您不能将表格布局设置为固定,然后通过将每个宽度设置为总宽度除以单元格数来调整单元格大小吗?