表格单元格上的垂直文本溢出

时间:2018-02-05 03:31:06

标签: css css3

   .table {
  table-layout: fixed;
  }
  .text-overflow {
  display:block;
  overflow-y: scroll;
  white-space: nowrap;
  text-overflow: ellipsis;
  }

  .cell-4 {
  width: 200px;
  }

https://codepen.io/mstone6769/pen/dodJEz

如何在表格单元格上进行垂直溢出? 我尝试使用overflow-y但没有工作

2 个答案:

答案 0 :(得分:1)

overflow: scroll

.table {
  table-layout: fixed;
  width: 400px;
  /* Just for the example */
}

.text-overflow {
  display: block;
  overflow: scroll;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.cell-4 {
  width: 200px;
}
<div class="container-fluid">
  <h1>Text overflow in a table cell</h1>
  <table class="table">
    <thead>
      <tr>
        <th>Column 1</th>
        <th>Column 2</th>
        <th>Column 3</th>
        <th>Column 4</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>Cell 1</td>
        <td>Cell 2</td>
        <td>Cell 3</td>
        <td class="cell-4">
          <span class="text-overflow">Ccell 4 is really really long and needs to wrap because it's so long</span>
        </td>
      </tr>
    </tbody>
  </table>
</div>

答案 1 :(得分:0)

您必须允许文本换行.text-overflow更新后的css

.text-overflow {
  display: block;
  height: 20px;
  overflow: auto;
}