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

标签 css twitter-bootstrap

我正在使用 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/

相关文章:

javascript - jquery 函数仅在控制台中工作

javascript - 自定义 jQuery 倒计时 Ruby on Rails

html - 为什么表单在IE7/8中显示不正确?

javascript - 在 javascript 中创建轮播

javascript - 我可以将 <h1> 标记作为可点击的按钮吗?

jquery - CSS 和 Bootstrap CDN 未显示在所有页面上

css - 粘性页脚不适用于所有页面

javascript - href 不适用于下拉切换 - bootstrap

html - 推特 Bootstrap : make contents of a row or row-fluid not wrap and overflow

css - Twitter bootstrap 没有得到我想要的页面布局