CSS ellipsis with inline elements?

末鹿安然 提交于 2019-12-05 14:02:50

问题


I've adapted jQuery UI MultiSelect Widget so that the text would show all selected labels, but if too many elements are selected to display, the text would be trimmed and ellipsed. I've done it so:

.ui-multiselect .selected-text {
    display: block;
    max-width: 190px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

The only things that I don't like in that solution is that I had to set display: block to the element (span). Without it, the width parameter was ignored and the span expanded to the text size.

Is it possible to get ellipsis to work with inline elements (without changing display to block)? If so, how to achieve that?


回答1:


There is a display option that works as a half-way house between inline and block, designed for exactly this kind of situation...

it's called

display:inline-block;

Use this instead of block, and your element will still flow in your content as if it were inline, but will act as a block for its contents, which means your ellipsis should work.




回答2:


You cannot apply text-overflow to inline elements.

http://dev.w3.org/csswg/css-ui/#text-overflow



来源:https://stackoverflow.com/questions/17838265/css-ellipsis-with-inline-elements

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