CSS: limit element to 1 line

后端 未结 4 1028
清歌不尽
清歌不尽 2021-02-01 01:23

I want to limit a element to display only 1 line of text, with the remainder hidden (overflow:hidden), without setting a specific height. Is this possible with just CSS?

4条回答
  •  太阳男子
    2021-02-01 01:56

    use display block so it won't go beyond your parent element.

    p#foo{
        white-space: nowrap;
        overflow: hidden;
        display: block;
        text-overflow: ellipsis;
    }
    

提交回复
热议问题