若是文字超出父元素指定寬度,文字會自動換行,而連續不間斷數字和英文字母(沒有其餘字符)不會自動換行;web
描述:(1).單行文本溢出,顯示省略號;第一步(不換行):white-space:nowrop;(對於連續的數字或者英文字母可省略)瀏覽器
第二步(溢出隱藏)overflow:hidden;spa
第三步(文本溢出顯示省略號)text-overflow:ellipsis;(省略號)3d
eg:blog
![](http://static.javashuo.com/static/loading.gif)
結果:ip
![](http://static.javashuo.com/static/loading.gif)
(2)多行文本溢出,最後一行顯示省略號;it
- a.對於內核是webkit的瀏覽器(Google/Safari),能夠直接用CSS樣式;((溢出隱藏)overflow:hidden;(省略號)text-overflow:ellipsis;display:-webkit-box;(彈性盒模型);();設置彈性盒子 的子元素的排列方式 :-webkit-box-orient:vertical; );設置顯示文本的行數:-webkit-line-clamp:3;(最多顯示3行)eg:
![](http://static.javashuo.com/static/loading.gif)
- 結果:
![](http://static.javashuo.com/static/loading.gif)
- b.兼容各類瀏覽器的方法
- (1)利用僞類(IE6/IE7不支持)
- eg:
![](http://static.javashuo.com/static/loading.gif)
- 結果:
![](http://static.javashuo.com/static/loading.gif)
- (2)利用定位和padding-right
![](http://static.javashuo.com/static/loading.gif)
結果:
webkit