html - 当我设置 no-wrap 时,bootstrap 表列太宽

标签 html css bootstrap-table

我正在尝试让表格“正常”运行(我的意思是正常)

  • 使用我给定的宽度百分比
  • 不要换行,任何溢出都使用省略号

Bootstrap 说我可能有 width 我在 th 标签样式标记中内联指定为最大宽度百分比

 table.table.table-striped.table-bordered th,
 table.table.table-striped.table-bordered th.text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

enter image description here https://jsfiddle.net/DTcHh/87084/

我指定的无环绕高度 ...但不是两者都是

  /* CSS used here will be applied after bootstrap.css */

table.table.table-striped.table-bordered td,
table.table.table-striped.table-bordered td.text {
  /*max-width: 177px;*/
}

table.table.table-striped.table-bordered td,
table.table.table-striped.table-bordered td.text, 
table.table.table-striped.table-bordered th,
table.table.table-striped.table-bordered th.text, 
table.table.table-striped.table-bordered span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

enter image description here https://jsfiddle.net/n85026uy/

但是我该怎么做才能使页面不换行(仅一行)但同时遵守我给它的内联 %。

不仅省略号没有运行,而且一个巨大的可笑水平滚动条出现在页面之外(在底部),而且底部导航 tfooter 控件被推到屏幕右侧。

我想要:

  • 使用的内联百分比
  • 如果太窄,请使用省略号并且不要换行。

不应该这么难

最佳答案

使用这些 CSS 样式:

为你的

        table-layout: fixed;

对于 th, td

        white-space: nowrap;
        text-overflow: ellipsis;
        overflow: hidden;

并为您的第 th 元素使用 inline(不是 CSS 规则,这很重要)width(不是 max-width),如下所示:

<th style="width: 11%" ... >

您可以自由使用 px 而不是 % 或其他单位

tested in Chrome

额外的滚动可能是因为使用了 '.row' 类,它增加了一些负边距。您必须确保通过使用适当的包装器/容器类/样式来补偿它

关于html - 当我设置 no-wrap 时,bootstrap 表列太宽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52038635/

相关文章:

javascript - Bootstrap Table更新结果

html - Bootstrap-Table Extension - 表格容器下行弹出的下拉列表

html - 如何让flex-grow忽略填充?

javascript - 防止我调整页面的所有内容

html - 如何为 <li> 元素添加带圆底 Angular 的 border-top?

html - 如何使用 Bootstrap 使一个 div 可滚动而另一个不可滚动

CSS 下拉可见性问题

jquery - wenzhixin bootstrap-table明细 View (子行)未初始化

html - 使Facebook嵌入页面在一定宽度上消失

javascript - 使用 Bootstrap Table 插件,如何在首次加载时设置搜索字符串?