html - 在这种情况下文本溢出如何

标签 html css css-tables

我想在这个表中文本覆盖流数据,我尝试了很多方法让它工作,但有些方法它在 Firefox 中也能工作,我想让它在 IE 中工作。

而且方法不是使用 Bootstrap ,而是完成它。

在这种情况下,正确的 CSS 是什么。

这是我的 CSS 代码示例:

.table {
        width: 450px;
        max-width: 450px;
      }
      .col-1 {
        width: 30%;
        max-width: 30%;
        overflow: hidden;
        text-overflow: clip !important;
        white-space: nowrap;
        word-wrap: break-word;
      }
      .col-2 {
        width: 40%;
        max-width: 40%;
        overflow: hidden;
        text-overflow: clip !important;
        white-space: nowrap;
        word-wrap: break-word;
      }
      .col-3 {
        width: 30%;
        max-width: 30%;
        overflow: hidden;
        text-overflow: clip !important;
        white-space: nowrap;
        word-wrap: break-word;
      }
<table class="table" border="0" cellspacing="5" cellpadding="5">
      <tbody>
        <tr>
          <td class="col-1">longgggggggggggggg gggggggggggg</td>
          <td class="col-2">longgggggggggggggg ggggggggggggg</td>
          <td class="col-3">longgggggggggggggg ggggggggggggg</td>
        </tr>
        <tr>
          <td class="col-1">longerrrrrrrrrrrrrrrrrrrrrrrrrr rrrrrrrrrrrrrrrrrrrrrrr</td>
          <td class="col-2">longerrrrrrrrrrrrrrrrrrrrrrrrrr rrrrrrrrrrrrrrrrrrrrrrr</td>
          <td class="col-3">longerrrrrrrrrrrrrrrrrrrrrrrrrr rrrrrrrrrrrrrrrrrrrrrrr</td>
        </tr> 
        <tr>
          <td class="col-1">longestttttttttttttttttttttttttttttttt tttttttttttttttttttttttttttttt</td>
          <td class="col-2">longestttttttttttttttttttttttttttttttt tttttttttttttttttttttttttttttt</td>
          <td class="col-3">longestttttttttttttttttttttttttttttttt tttttttttttttttttttttttttttttt</td>
        </tr>
      </tbody>
    </table>

最佳答案

默认情况下,表格单元格的宽度必须与其内容一样宽。

但是您可以使用 table-layout: fixed 切换到忽略内容的更快、更可靠的布局模式。

.table {
  width: 450px;
  table-layout: fixed;
}
td {
  overflow: hidden;
  white-space: nowrap;
}
.col-1, .col-3 {
  width: 30%;
}
.col-2 {
  width: 40%;
}
<table class="table" border="0" cellspacing="5" cellpadding="5">
  <tbody>
    <tr>
      <td class="col-1">longgggggggggggggg gggggggggggg</td>
      <td class="col-2">longgggggggggggggg ggggggggggggg</td>
      <td class="col-3">longgggggggggggggg ggggggggggggg</td>
    </tr>
    <tr>
      <td class="col-1">longerrrrrrrrrrrrrrrrrrrrrrrrrr rrrrrrrrrrrrrrrrrrrrrrr</td>
      <td class="col-2">longerrrrrrrrrrrrrrrrrrrrrrrrrr rrrrrrrrrrrrrrrrrrrrrrr</td>
      <td class="col-3">longerrrrrrrrrrrrrrrrrrrrrrrrrr rrrrrrrrrrrrrrrrrrrrrrr</td>
    </tr>
    <tr>
      <td class="col-1">longestttttttttttttttttttttttttttttttt tttttttttttttttttttttttttttttt</td>
      <td class="col-2">longestttttttttttttttttttttttttttttttt tttttttttttttttttttttttttttttt</td>
      <td class="col-3">longestttttttttttttttttttttttttttttttt tttttttttttttttttttttttttttttt</td>
    </tr>
  </tbody>
</table>

关于html - 在这种情况下文本溢出如何,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40519184/

相关文章:

html - 将简单文本插入到 iframe 中?不是 .htm 文件

css - 正确的 CSS 语法

html - 父容器不扩展到子元素

html - CSS 使 tds 在表格中重叠

javascript - 在没有 jQuery 的情况下使用 JavaScript 在选项卡中创建选项卡

javascript - 如何在 javascript 中为 html 样式添加描边?

html - DIV 不应用对齐

html - Flexbox 导航下拉菜单不在容器下

HTML CSS 表格布局

html - 如何使用 div 对齐表格之类的表格?