How to trigger text-overflow: ellipsis on multi-line element [duplicate]

北城余情 提交于 2019-12-12 02:05:50

问题


I have this element that contains a string which exceeds the space available. Text should be displayed on two lines only. I need text-overflow: ellipsis to be triggered but it's not happening here. What am I doing wrong?

<div><span>IpsumLorem Traborditum orb Porfalohyrm</span></div>
div{
    text-overflow: ellipsis;
    overflow: hidden;
    float: left;
    line-height: 20px;
    padding: 8px 6px 6px;
    height: 44px;
    width: 133px;
}

JSFiddle


回答1:


You need white-space: nowrap; for text-overflow: ellipsis; to work properly: http://jsfiddle.net/DHge3/3/




回答2:


Remove padding from your CSS and it will work fine

CSS

div {
    line-height: 20px;
    height: 44px;
    width: 133px;
    overflow: hidden;
    text-overflow: ellipsis;
}

FIDDLE



来源:https://stackoverflow.com/questions/14596777/how-to-trigger-text-overflow-ellipsis-on-multi-line-element

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!