css文本溢出处理

DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>文本溢出处理title>
    <style>
      .sing-line {
        border: 2px solid black;
        width: 200px;
        height: 30px;
        line-height: 30px;
        margin-bottom: 90px;
        color: #f40;
        /* 强制不换行 */
        white-space: nowrap;
        /* 溢出隐藏 */
        overflow: hidden;
        /* 文本溢出省略号 */
        text-overflow: ellipsis;
      }
      .multi-line {
        border: 2px solid black;
        width: 200px;
        height: 150px;
        line-height: 30px;
        /* 改变盒子 存在兼容性问题 */
        display: -webkit-box;
        /* 排列方向 */
        -webkit-box-orient: vertical;
        /* 设置显示几行 */
        -webkit-line-clamp: 3;
        overflow: hidden;
      }

      /* 多行文本溢出无兼容性问题实现 */
      .container {
        height: 140px;
        width: 400px;
        padding: 20px;
        background: #ccc;
        overflow: hidden;
      }
      .text-container {
        height: 100px;
        overflow: hidden;
      }
      .content {
        line-height: 25px;
        margin-top: -80px;
      }
      .more {
        float: right;
        /* 设置行高为 相对于字体大小的倍数, 1是使用浏览器默认行高 */
        line-height: 1;
      }
      .text-container::before {
        content: "";
        display: block;
        height: 80px;
      }
    style>
  head>
  <body>
    
    <p class="sing-line">
      This is a single line of text This is a single line of text This is a
      single
    p>
    
    <p class="multi-line">
      This is a multi line of text This is a multi line of text This is a Thisis
      a multi line of text This is a, This is a
    p>
    <div class="container">
      <div class="text-container">
        <div class="more">...div>
        <div class="content">
          This is a multi line of text This is a multi line of text This is a
          Thisis a multi line of text This is a multi line of text This is a
          multi line of text This is a Thisis a multi line of text This is a
          multi line of text This is a multi line of text This is a Thisis a
          multi line of text This is a multi line of text This is a multi line
          of text This is a Thisis a multi line of text This is a multi line of
          text This is a multi line of text This is a Thisis a multi line of
          text This is a multi line of text This is a multi line of text This is
          a Thisis a multi line of text This is a multi line of text This is a
          multi line of text This is a Thisis a multi line of text This is a
          multi line of text This is a multi line of text This is a Thisis a
          multi line of text
        div>
      div>
    div>
  body>
html>

css文本溢出处理_第1张图片

你可能感兴趣的:(css,前端,html)