html+css文本超出显示省略号

text-overflow语法:
text-overflow : clip | ellipsis

text-overflow参数值和解释:
clip :  不显示省略标记(...),而是简单的裁切
ellipsis :  当对象内文本溢出时显示省略标记(...)

text-overflow应用说明:
CSS text-overflow设置或检索是否使用一个省略号标记(...)标示对象内文本文字的溢出。

简单理解:就是我要把文本限制在一行(white-space: nowrap;),肯定这一行是有限制的(width),并且你的溢出的部分要隐藏起来(overflow: hidden;),然后出现省略号( text-overflow: ellipsis)。

下面给出例子:
可运行修改的:
代码片段 1

<!DOCTYPE html>
<html>

    <head>
        <meta charset="utf-8">
        <title></title>
        <style type="text/css">
            p {
                width: 200px;
                height: 200px;
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
                border: 1px solid red;
            }
        </style>
    </head>

    <body>
        <p>省略号省略号省略号省略号省略号省略号省略号省略号省略号</p>
    </body>

</html>
posted @ 2022-09-29 14:13  与君别  阅读(158)  评论(0编辑  收藏  举报