在我的表格中,我设置列中第一个单元格的宽度为100px。 但是,当此列中的某个单元格中的文本太长时,列的宽度就会超过100px。如何禁用此扩展?
当前回答
您需要在相应的CSS中编写这些内容
table-layout:fixed;
其他回答
如果不想要固定的布局,请指定一个类,使列的大小适当。
CSS:
.special_column { width: 120px; }
HTML:
<td class="special_column">...</td>
你不需要设置“fixed”-你只需要设置overflow:隐藏,因为列宽度已经设置好了。
凯旋的想法是对的。这是正确的代码…
<style type="text/css">
th.first-col > div,
td.first-col > div {
overflow:hidden;
white-space:nowrap;
width:100px
}
</style>
<table>
<thead><tr><th class="first-col"><div>really long header</div></th></tr></thead>
<tbody><tr><td class="first-col"><div>really long text</div></td></tr></tbody>
</table>
如果对表的访问受限,那么使用类或内联样式可能会比较复杂。
或者你也可以瞄准每一行的第一个td和第th个子元素(也就是第一列)
当我用width测试它时,下面的规则对我有用,但由于某种原因,max-width不适用:
thead, tbody tr {
display:table;
width:100%;
table-layout:fixed;
}
tr th:first-child, tr td:first-child {
width:100px;
}
我用了这个
.app_downloads_table tr td:first-child {
width: 75%;
}
.app_downloads_table tr td:last-child {
text-align: center;
}
推荐文章
- 在网页上用鼠标模拟震颤(例如帕金森病)?
- Bootstrap抛出Uncaught错误:Bootstrap的JavaScript需要jQuery
- 如何改变文本区域的边框颜色:焦点
- 我如何设置背景颜色为文本的宽度,而不是整个元素的宽度,使用CSS?
- 如何删除和清除所有的本地存储数据
- 设备像素比到底是什么?
- 我如何做一个半透明的背景?
- 强制打开“另存为…”弹出打开文本链接点击PDF在HTML
- 如何修改标签文本?
- 在CSS网格布局中等高行
- $(window).width()与媒体查询不一样
- 在HTML中还有其他有用的空格码吗,比如半空格的 , em-spaces, en-spaces等等?
- 输入触发器按钮单击
- 如何以及在哪里使用::ng-deep?
- Angular 2模板中的标签是什么意思?