欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

CSS隐藏文本溢出并用省略号代替

程序员文章站 2022-04-22 14:02:06
...
  • 单行文本溢出隐藏

CSS隐藏文本溢出并用省略号代替

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 100px;
            border: 1px solid grey;
        }
        span {
            /* 单行文本溢出隐藏 */
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            display: block;  
        }
    </style>
</head>
<body>
    <div><span>单行文本换行和多行文本换行</span></div>
</body>
</html>
  • 多行文本溢出隐藏

CSS隐藏文本溢出并用省略号代替

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 100px;
            border: 1px solid grey;
        }
        span {
            /* 多行文本溢出隐藏 */
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 2;/*显示行数*/
        }
    </style>
</head>
<body>
    <div><span>单行文本换行和多行文本换行</span></div>
</body>
</html>
相关标签: css html