【发布时间】:2016-07-25 21:14:21
【问题描述】:
我的代码显示一个表格。每个表格行都以一个标题单元格开始,然后是一个标准单元格。
某些表格行包含一个附加标题单元格,位于标准单元格之后。
如果标准单元格后面有标题单元格,我想自动调整它们的大小。我希望每个表格行都适合表格的宽度边界。
我不希望重新调整标题单元格的大小,只调整标准单元格以适应表格行中的标题单元格。
This is what the table looks like
This is what I want it to look like
只有标准单元格被重新调整大小以适应下面的标题单元格,以匹配表格中其他行的宽度。
<html>
<head>
<link href='https://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
<style>
body {
color: #FFF;
font-family: 'Open Sans', sans-serif;
text-shadow: -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000;
}
table {
border-collapse: collapse;
font-size: 25px;
margin: auto;
width: 500px;
}
th,
td {
border: 1px solid black;
height: 50px;
padding: 5px;
text-align: center;
}
th {
background-color: #8000FF;
color: #FFF;
width: 50px;
}
td {
width: 350px;
}
table tr:nth-child(odd) td {
background-color: #FF8000;
}
table tr:nth-child(even) td {
background-color: #00FF80;
}
</style>
</head>
<body>
<table>
<tbody>
<tr>
<th>18</th>
<td>LqtgHRqNcW</td>
</tr>
<tr>
<th>91</th>
<td>BhydHJUADT</td>
</tr>
<tr>
<th>85</th>
<td>frvFQoRUuC</td>
<th>5214</th>
</tr>
<tr>
<th>06</th>
<td>tIfFHLblmN</td>
<th>8808</th>
</tr>
<tr>
<th>49</th>
<td>HMPbrfKYcN</td>
</tr>
<tr>
<th>68</th>
<td>mMxIjEQMgD</td>
</tr>
<tr>
<th>39</th>
<td>dDFSkkkLww</td>
</tr>
<tr>
<th>57</th>
<td>vMvOZYyLIB</td>
<th>3235</th>
</tr>
<tr>
<th>12</th>
<td>AKWQsKDNpr</td>
</tr>
<tr>
<th>58</th>
<td>oCNXiRSwOO</td>
</tr>
</tbody>
</table>
</body>
</html>
https://jsfiddle.net/yb1hcy7q/
如何自动调整标准表格单元格的大小以适应表格宽度内的标题单元格?
感谢您阅读我的问题,我将不胜感激。
【问题讨论】: