zoukankan      html  css  js  c++  java
  • CSS控制文字,超出部分显示省略号

    <p style=" 300px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;">

    效果如图:
    dome1

    实现方法:

    overflow: hidden;
    text-overflow:ellipsis;
    white-space: nowrap;

    效果如图:
    dome2

    实现方法:

    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    overflow: hidden;


    效果如图:

    dome3

    实现方法:

    p{position: relative; line-height: 20px; max-height: 40px;overflow: hidden;}
    p::after{content: "..."; position: absolute; bottom: 0; right: 0; padding-left: 40px;
    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%);
    }

    适用范围:
    该方法适用范围广,但文字未超出行的情况下也会出现省略号,可结合js优化该方法。

    注:

      1. 将height设置为line-height的整数倍,防止超出的文字露出。
      2. 给p::after添加渐变背景可避免文字只显示一半。
      3. 由于ie6-7不显示content内容,所以要添加标签兼容ie6-7(如:<span>…<span/>);兼容ie8需要将::after替换成:after。
    
    
     
    徐增友
  • 相关阅读:
    java环境配置为1.7jdk为什么cmd java -version查看版本是1.8
    bulid path 引 jar包 步骤
    eclipse 报错
    PLSQL使用技巧
    Oracle sqlplus不是内部或外部命令
    SVN 插件安装到Myeclipse10 上(经典)
    socket学习
    Eclipse 配置 插件svn 包步骤
    如何在Eclipse中使用SVN(经典)
    linux 下搭建LAMP
  • 原文地址:https://www.cnblogs.com/xzybk/p/11265428.html
Copyright © 2011-2022 走看看