我的省略号有问题.以下是我的HTML:

<div id="wrapper">
    <span id="firstText">This text should be effected by ellipsis</span>
    <span id="lastText">this text should not change size</span>
</div>

有没有办法用纯CSS来做到这一点呢? 以下是我try 过的:

#firstText
{
    overflow: hidden;
    white-space:nowrap;
    text-overflow:ellipsis;
}

#lastText
{
    white-space:nowrap;
    overflow:visible;   
}

这是如何显示的:

This text should be effected by ellipsis this text shoul

虽然这是我想要的结果:

This text should be e...this text should not change size

推荐答案

你可以这样给你的#firstTextwidth分:

#firstText
{
    overflow: hidden;
    white-space:nowrap;
    text-overflow:ellipsis;
    width:150px;
    display:inline-block;
}

判断此示例

http://jsfiddle.net/Qhdaz/5/

Css相关问答推荐

在react native中应用阴影

Safari CSS扫描动画效果不起作用

VueJS3+Vutify中缺少一些CSS类

如何在CSS中创建水平/垂直对称的虚线边框?

关闭Superset中的Deck.gl工具提示

.NET 8 预览版 6 中不使用新项目模板提供 Blazor CSS 文件

在具有特定类的 td 之后,如何编写适用于该行上所有 td 元素的表行的 CSS Select 器?

我怎样才能准确地获得虚构文本内容宽度的边距?

Material UI Modal 因背景而变暗

semantic-ui-react 使输入使用全宽度可用

如何使用 TailwindCSS 水平设置输入和按钮

如何应用适当样式的元素加消息框?

如何为使用jsTreeR拖入层次 struct node 的元素添加顺序编号?

如何在每一行周围放置不同大小的阴影?

CSS类和id同名

Bootstrap 4 img-circle 类似乎不存在

加载资源失败:服务器响应状态为 404(未找到)

字体上的 Font-Awesome 错误 404

Flexbox 代码适用于除 Safari 之外的所有浏览器.为什么?

bootstrap 关闭响应菜单点击