CSS控制文本的长度 超过一行显示省略号的实现方法

版权声明:我的博客 © lidianchun.com | https://blog.csdn.net/qq_36120267/article/details/81946503

html代码如下

<style type="text/css">
    .row{
        width:100px;height:20px;
    }
    .ellipsis{
        text-overflow:ellipsis; 
        white-space:nowrap; 
        overflow:hidden; 
    }
</style>
<div class="row ellipsis">这是一句示例的文字,这里要写得非常长,因为文本溢出css3才能有效果 </div>

text-overflow属性仅是注解,当文本溢出时是否显示省略标记。并不具备其它的样式属性定义。我们想要实现溢出时产生省略号的效果。还必须定义:强制文本在一行内显示(white-space:nowrap)及溢出内容为隐藏(overflow:hidden)。只有这样才能实现溢出文本显示省略号的效果。 

仅定义text-overflow:ellipsis; 不能实现省略号效果。   

定义text-overflow:ellipsis; white-space:nowrap; 同样不能实现省略号效果   

同时应用: text-overflow:ellipsis; white-space:nowrap; overflow:hidden; 可实现所想要得到的溢出文本

综上,超过一行就能显示省略号了

猜你喜欢

转载自blog.csdn.net/qq_36120267/article/details/81946503