css文字溢出处理

一:单行文字溢出容器要打点展示

1.单行文本

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
  <p>苹果iPhone12国行版售价曝光:全系5G 最低5499元</p>
</body>
<style>
    * {
     
     
        margin: 0;
        padding: 0;
    }
  p{
     
     
      border: 1px solid black;
      width: 300px;
      height: 30px;
      line-height: 20px;
      
      /* 处理 */
      /* 单行显示 */
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;

  }
</style>

</html>

2.多行文本

height表示垂直高度,line-height表示文本行高,也就是从文字顶部到底部的距离
height是line-height的两倍只能展示两行,height是line-height的三倍展示三行

多行做截断处理

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
  <p>苹果iPhone12国行版售价曝光:全系5G 最低5499元
    苹果iPhone12国行版售价曝光:全系5G 最低5499元
  </p>
</body>
<style>
    * {
     
     
        margin: 0;
        padding: 0;
    }
  p{
     
     
     
      border: 1px solid black;
      width: 300px;
      height: 40px;
      line-height: 20px;
      overflow: hidden;
  }
</style>

</html>

猜你喜欢

转载自blog.csdn.net/x1037490413/article/details/108500615