【发布时间】:2017-01-30 23:11:47
【问题描述】:
我正在尝试使用 calc 来修复我的 th:last-child 的宽度,该宽度与其他宽度相差 15 像素。我所做的是:
th:last-child {
width: calc( (100% - 30px)/12 + 30px );
}
table, tr {
width:100%;
border: 1px solid black;
height:10px;
}
th {
border-right: 1px solid black;
width: calc( (100% - 30px)/12 );
}
<table>
<thead>
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
<th>Column 4</th>
<th>Column 5</th>
<th>Column 6</th>
<th>Column 7</th>
<th>Column 8</th>
<th>Column 9</th>
<th>Column 10</th>
<th>Column 11</th>
<th>Column 12</th>
</tr>
</thead>
<tbody>
<tr>
<td>Row 1</td>
<td>Row 2</td>
<td>Row 3</td>
<td>Row 4</td>
<td>Row 5</td>
<td>Row 6</td>
<td>Row 7</td>
<td>Row 8</td>
<td>Row 9</td>
<td>Row 10</td>
<td>Row 11</td>
<td>Row 12</td>
</tr>
</tbody>
</table>
我除以 12,因为它是我表中的列数。据我了解 100% 被视为父级的宽度。问题是最后,我没有得到我所期望的,知道为什么吗?
【问题讨论】:
-
请分享您的标记。
-
你能提供一段 html 代码适用于这个 css 吗?
-
表格单元格的宽度由它所在的列决定,如果你需要它更宽,那么你需要在给定的单元格上使用
colspan(如果你想要它要更窄,您需要在同一列中的其他单元格上使用colspan)。 -
我添加了我的小提琴
-
我猜你要找的是简单的 padding-left 或 padding-right