ITeye博客

CSS3 text-overflow 文本溢出

小丑鱼0703 · 2015-01-20 10:08 · CSS3 · Web前端 · Markdown

text-overflow 属性规定当文本溢出包含元素时发生的事情。 语法:text-overflow: clip|ellipsis|string; clip 修剪文本。 ellipsis 显示省略符号来代表被修剪的文本。

注意:text-overflow:ellipsis;要与white-space:nowrap; 和overflow:hidden; 一起使用才有效果。因为text-overflow只是用来说明文字溢出时用什么方式显示,要实现溢出时产生省略号的效果,还须定义强制文本在一行内显示(white-space:nowrap)及溢出内容为隐藏(overflow:hidden),只有这样才能实现溢出文本显示省略号的效果

<div class="test" >This is some long text that will not fit in the box</div>

div.test{
white-space:nowrap;
overflow:hidden;  
text-overflow:clip;
width:12em; 
border:1px solid #000000;
}

效果:


div.test{
white-space:nowrap;
overflow:hidden;  
text-overflow:ellipsis;
width:12em; 
border:1px solid #000000;
}

效果:

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。