css
主页 > 网页 > css >

CSS文字溢出:ellipsis在IE上不起效果的解决

2023-11-26 | 佚名 | 点击:

单行文本的溢出显示省略号

1

2

3

4

5

p {

    overflow: hidden;

    text-overflow: ellipsis;

    white-space: nowrap;

}

多行文本的溢出显示省略号

方法一:

1

2

3

4

5

6

7

p {

    display: -webkit-box;

    -webkit-box-orient: vertical;

    -webkit-line-clamp: 3;

    overflow: hidden;

    text-overflow: ellipsis;

}

适用范围:
因使用了WebKit的CSS扩展属性,该方法适用于WebKit浏览器及移动端;不兼容IE浏览器。

方法二:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

p {

    position:relative;

    line-height:20px;

    height:60px;

    overflow:hidden;

}

p::after {

    content:"...";

    position:absolute;

    bottom:0;

    right:0;

    padding-left:45px;

    background: -webkit-linear-gradient(left, transparent, #fff 55%);

    background: -o-linear-gradient(right, transparent, #fff 55%);

    background: -moz-linear-gradient(right, transparent, #fff 55%);

    background: linear-gradient(to right, transparent, #fff 55%);

}

局限性:
该方法能在谷歌和IE浏览器上出现文字超过就省略的效果,但是不出现…省略号!

原文链接:
相关文章
最新更新