在表中使用calc()

Joa*_*ska 6 css css3 css-calc

我试图用它calc来固定我的宽度th:last-child与其他宽度相差15px.我所做的是:

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 );
}
Run Code Online (Sandbox Code Playgroud)
<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>
Run Code Online (Sandbox Code Playgroud)

JS小提琴再现.

我除以12因为它是我表中的列数.据我所知,100%被视为父母的宽度.问题是,最后,我没有得到我所期望的,任何想法为什么?

Paw*_*ski 4

您必须将table-layout属性设置为“固定”。

请参阅对表格使用 calc()

和工作示例: https: //jsfiddle.net/rpyydd5n/3/