html - 带表格的文本溢出省略号

标签 html css

我有一个使用 box-center 类居中的布局。现在我想添加文本溢出省略号,但它不再居中。

.box-center {
  display: table;
  table-layout: fixed;
  margin: 0 auto;

  .ellipsed {
    display: table;
    table-layout: fixed;
    white-space: nowrap;
    width: 100%;

    span {
      display: table-cell;
      overflow: hidden;
      text-overflow: ellipsis;
    }
  }
}

我也试过添加这个,但这不是文本溢出省略号。

.ellipsed {
  white-space: nowrap;
  width: 100%;

  span {
    display: inline-block;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

HTML:

<div class="box-center">
  <div class="ellipsed">
    <span>Some text to be ellipsed</span>
  </div>
</div>

有人可以帮忙吗?

最佳答案

每当你想使用 text-overlfow:ellipsis 时,你需要定义元素的宽度,因为你需要告诉元素在什么宽度之后它应该隐藏和显示省略号。

请参阅这个基于简单 CSS 的虚拟示例。我只添加了一个虚拟宽度及其工作

.ellipsed {
  white-space: nowrap;
  width: 100%;
}

span {
  display: inline-block;
  overflow: hidden;
  text-overflow: ellipsis;
  width:100%;
}
<div class="box-center">
  <div class="ellipsed">
    <span>Some text to be ellipsed Some text to be ellipsed Some text to be ellipsed Some text to be ellipsed Some text to be ellipsed Some text to be ellipsed Some text to be ellipsed Some text to be ellipsed Some text to be ellipsed Some text to be ellipsed Some text to be ellipsed Some text to be ellipsed Some text to be ellipsed Some text to be ellipsed Some text to be ellipsed Some text to be ellipsed </span>
  </div>
</div>

关于html - 带表格的文本溢出省略号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38200140/

相关文章:

javascript - 向 window.location 发送一个变量,该变量从数据库中获取

html - Bootstrap 切换菜单图标在小型设备上不起作用

CSS 选择器在 2 个元素之后跳 1 个元素

html - 为什么样式表只适用于索引页,而不适用于索引页的任何扩展? (使用 Jinja 的模板)

html - 删除文本之间存在的额外空间

Javascript:onchange使用相同的div并从2个不同的id打印

使用 Onclientclick 或 Onsubmit 都不会调用 JavaScript 函数

Javascript createElement 在 IE 中不起作用

javascript - 如何使用javascript或jquery在新窗口中打印特定的<div>内容?

javascript - 将文本放在 javascript 形状内?