Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css 如何控制最后一列的宽度?_Css - Fatal编程技术网

Css 如何控制最后一列的宽度?

Css 如何控制最后一列的宽度?,css,Css,当我将宽度添加到td时,它会使th变大 如果最后一列有很多文本,但我不希望宽度显示在整个页面中,我如何控制它 我仍然希望th为nowrap,“替换”和“附加测试”始终为是/否文本 我犯了一个错误 使用css选择器查找最后一个,并对其应用最大宽度: table.standardtable tr td:last-child{ /* last-child returns the last instance of the td */ max-width:150px; /* addition

当我将宽度添加到td时,它会使th变大

如果最后一列有很多文本,但我不希望宽度显示在整个页面中,我如何控制它

我仍然希望
th
nowrap
,“替换”和“附加测试”始终为是/否文本

我犯了一个错误


使用css选择器查找最后一个
,并对其应用最大宽度:

 table.standardtable tr td:last-child{ /* last-child returns the last instance of the td */
   max-width:150px;
   /* additional styles as required */
 }

小提琴上要注意的一点是,不要将
混合使用
是一个表头,其中as
是一个常规单元格。虽然从技术上讲,您的标记是有效的,但这不是一个好的实践

有效的表将类似于:

<table>
<tr>
 <th></th>
 <th></th>
 <th></th>
</tr>
<tr>
 <td></td>
 <td></td>
 <td></td>
</tr>
</table>

如果要更改标记,请改用
css类

<table>
<tr>
 <th></th>
 <th></th>
 <th></th>
</tr>
<tr>
 <td></td>
 <td></td>
 <td></td>
</tr>
</table>