常用css

一丝心情 / 2023-05-09 / 原文

  1. 单行省略
    /*
    * 强制不换行: white-space: nowrap;
    * 超出隐藏: overflow: hidden
    * 超出的文本显示省略号: text-overflow: ellipsis;
    * 需要设置宽度
    */
    .t-ellipsis {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        /* width: 100%; */
    }
  2. 多行省略
    /*
    * 超出隐藏: overflow:hidden;
    * 超出的文本显示省略号: text-overflow: ellipsis;
    * 设置弹性盒模型: display:-webkit-box;
    * 设置弹性盒子 的子元素的排列方式 : -webkit-box-orient:vertical;
    * 显示文本的最多显示行数:-webkit-line-clamp:3;
    * 需要设置宽度
    */
    .t-ellipsis_3 {
        overflow:hidden;
        text-overflow: ellipsis;
        display:-webkit-box;
        -webkit-box-orient:vertical;
        -webkit-line-clamp:3;
        /* width: 100%; */
    }
  3. 其他