Home  >  Article  >  Web Front-end  >  CSS控制文本的长度,超过一行显示省略号_html/css_WEB-ITnose

CSS控制文本的长度,超过一行显示省略号_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:20:461025browse

代码如下:

<div style="width:100px;height:20px;text-overflow:ellipsis; white-space:nowrap; overflow:hidden; ">a b c d e f g h i j k l , msa sd sd sa w df f </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; 可实现所想要得到的溢出文本

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn