gpt4 book ai didi

css - 使用 twitter bootstrap,我怎样才能做到在不破坏列的情况下表格中没有自动换行?

转载 作者:太空宇宙 更新时间:2023-11-04 10:11:06 25 4
gpt4 key购买 nike

我正在使用 Bootstrap 并试图在 tabletd 元素中禁用自动换行。我已将 white-space: nowrap 应用于 td 元素,这会按预期禁用自动换行,但现在 table 本身将跨越超出它所在的列。因此,仅此 CSS 似乎就破坏了 Bootstrap 。

我现在想使用 text-overflow: ellipsis,这样任何想要自动换行的文本都会被省略号截断。不过,我似乎无法将此 CSS 应用于任何内容并使其正常工作。无论我在哪里应用它,似乎都没有发生任何事情。表格总是扩展到所需的网格列之外。

如何在 td 元素中禁用换行,并使用省略号截断文本而不破坏网格?

最佳答案

这是这篇文章中的一个技巧 Fluid table with td nowrap & text-overflow?效果很好:

<td>里面放一个div包含文本,然后为 div 设置样式:

text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
width: 0;
min-width: 100%;

即表看起来像:

<div class="container">
<div class="row">
<div class="col-md-12">
<table class="table table-striped">
<thead>
<tr>
<th>#</th>
<th>First Name</th>
<th>Last Name</th>
<th>Username</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">1</th>
<td>
<div style= "text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
width: 0;
min-width: 100%;">
Mark really long text that need to be wrapped ywey yd syd ysd syd skd ysyd sad ysd syjdk skjdy sjd hdhjd hjd hjd hjds hjds dhj dsjhds js hs jsd hjsdhs dhs djs
</div>

</td>
<td>Otto</td>
<td>@mdo</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>

关于css - 使用 twitter bootstrap,我怎样才能做到在不破坏列的情况下表格中没有自动换行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37604606/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com