zoukankan      html  css  js  c++  java
  • 多行文本溢出显示省略号,并兼容IE

    原文:https://blog.csdn.net/janessssss/article/details/80450819

    //单行文本溢出显示省略号
    overflow: hidden;
    text-overflow:ellipsis;
    white-space: nowrap;

    这种方法适用范围只局限与浏览器内核是webkit的,不兼容ie

    //多行文本溢出显示省略号
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    overflow: hidden;

    下面这种方法是可行的,可以兼容ie

    p {
       position: relative;
        line-height: 17px;
        overflow: hidden;
    
    }
    .p-after:after{
        content: "..."; 
        position: absolute; 
        bottom: 0; 
        right: 0; 
        padding-left: 40px;
        background: -webkit-linear-gradient(left, transparent, #fff 55%);
        background: -moz-linear-gradient(left, transparent, #fff 55%);
        background: -o-linear-gradient(left, transparent, #fff 55%);
        background: linear-gradient(to right, transparent, #fff 55%);
    }
    

    js

    $(function(){
     //获取文本的行高,并获取文本的高度,假设我们规定的行数是五行,那么对超过行数的部分进行限制高度,并加上省略号
       $('p').each(function(i, obj){
            var lineHeight = parseInt($(this).css("line-height"));
            var height = parseInt($(this).height());
            if((height / lineHeight) >5 ){
                $(this).addClass("p-after")
                $(this).css("height","85px");
            }else{
                $(this).removeClass("p-after");
            }
        });
    })
  • 相关阅读:
    poj3660 最短路/拓扑序
    poj1502 最短路
    poj3259 最短路判环
    poj1680 最短路判环
    一些自己常用的cdn
    bower
    vuejs点滴
    jquery的ajax
    jquery点滴
    githubpage+hexo构建自己的个人博客
  • 原文地址:https://www.cnblogs.com/xi-li/p/14821256.html
Copyright © 2011-2022 走看看