html - 带 CSS 的响应式表格列

标签 html css

有一个包含三列的表格,第一列和最后一列是固定的,中间的列应该是可变的。

问题 - 中间栏内有带有 nowrap 的文本,它阻止了它的流动性。

如何做到这一点?

它在宽页面上的外观(正确的行为):

enter image description here

它在窄页面上的外观:

enter image description here

它在窄页面上的实际外观(不正确的行为,请参见滚动条):

image

代码 https://jsfiddle.net/8c9msa71/

td {
  border: 1px solid black;
}

.fluid {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
<table>
  <tr>
    <td>first</td>
    <td class="fluid">very-very-very-very-very-very-long-second-text</td>
    <td>third</td>
  </tr>
</table>

最佳答案

你可以通过添加一个div来做到这一点

td { border: 1px solid black; }
.fluid { position: relative; width: 70%;}
.fluid div {
  white-space: nowrap; 
  overflow: hidden;
  text-overflow: ellipsis;
  position: absolute;
  left: 5px;
  right: 5px;
  top: 0;
}
<table width="100%">
  <tr>
    <td>first</td>
    <td class="fluid">
    <div>very-very-very-very-very-very-long-second-text</div>
    </td>
    <td>third</td>
  </tr>
</table>

关于html - 带 CSS 的响应式表格列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44041840/

相关文章:

html - 具有动态大小的列表

javascript - 在高级搜索选项卡抽屉中实现页脚

css - 如何在 Bootstrap 5 中将导航元素向右对齐?

Javascript:根据值自动提交表单? (有短暂的延迟)

javascript - 我想在页面准备好时使用 jquery 做一些事情(例如 $(window).ready()),但它似乎不起作用

javascript - Firefox 中断词的解决方法

css - 如何让SPAN没有背景

css - (React) 带有 css 模块的 CSSTransition

php - zend 如何在同一操作中验证 3 个单独的表单?

javascript - 如何将图像对齐到网格。 (我想用图片制作一个产品列表,点击它们会链接到相应的页面)