html - 具有多个跨度的文本溢出省略号

标签 html css

我有一个 div,其中包含三个 span 元素。三个 span 元素形成一个文本,我想将其限制在一行中。如果文本的宽度大于 div

,我想将省略号应用于文本

JSFiddle here

HTML:

<div class="box">
  <span>First text</span>
  <span>Second text</span>
  <span>Third long, long text</span>
</div>

CSS:

.box{
  border: 1px solid red;
  width: 200px;
}

最佳答案

我想这就是你想要的吧?

.box{
  border: 1px solid red;
  width: 200px;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

JSFiddle:https://jsfiddle.net/g56rffds/1/

关于html - 具有多个跨度的文本溢出省略号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34036788/

相关文章:

html - 如何查找当前页面使用了哪些 CSS 文件

html - 在 flex 容器中填充剩余的高度或宽度

javascript - 单击按钮 html、css、javascript 时显示更多信息

css - 在 joomla 2.5 中定位特定元素 css

javascript createElement/appendchild -- 单击后新文本消失

html - CSS 图像替换在 MSIE 7 和 8 中不起作用

javascript - iPhone/iPad 上的自动对焦表单元素

css - nth-child 和 nth-last-child 不一起工作

javascript - 如何在单词下方使用底部边框,长度有限且居中?

jquery - 如何让我的 TreeView 在进入子页面后显示数据?