How to use “text-overflow: ellipsis” with a label element? [duplicate]

廉价感情. 提交于 2019-12-13 15:22:00

问题


I have a label where I need to add an ellipsis to, but I can't get it to work:

<label id="div2">This is some long text that will not fit in the box</label>

label#div2 {
    white-space: nowrap; 
    width: 30px; 
    overflow: hidden;
    text-overflow: ellipsis; 
    border: 1px solid #000000;
}

JSFiddle


回答1:


To hide overflow in an element, the element needs to be block-level. But you probably don't want an inline label to be block-level because that could cause other issues. So just make it inline-block:

label#cats {
    white-space: nowrap; 
    width: 30px; 
    overflow: hidden;
    text-overflow: ellipsis; 
    border: 1px solid #000000;
    display: inline-block;
}

jsFiddle: http://jsfiddle.net/rdg221bx/1/



来源:https://stackoverflow.com/questions/25881293/how-to-use-text-overflow-ellipsis-with-a-label-element

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