如何使用 CSS 截断文本

html-css07

如何使用 CSS 截断文本,第1张

text-overflow语法:

text-overflow : clip | ellipsis

text-overflow参数值和解释:

clip :  不显示省略标记(...),而是简单的裁切

ellipsis :  当对象内文本溢出时显示省略标记(...)

text-overflow应用说明:

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

要想实现显示不完内容将显示省略号代替,还需要html nobr标签完成(nobr禁止换行标签)

用php或者其他的截取吧

,css好像只可以隐藏多余的

function

msubstr($str,$start,$len){

for($i=0$i<$start+$len$i++){

$tmpstr=(ord($str[$i])>=161

&&

ord($str[$i])<=247&&

ord($str[$i+1])>=161

&&

ord($str[$i+1])<=254)?$str[$i].$str[++$i]:$tmpstr=$str[$i]

if

($i>=$start&&$i<($start+$len))$tmp

.=$tmpstr

}

return

$tmp

}

这个是php截取类

<div style="widith:300pxheight:200pxbackground:url('背景图片地址') no-repeat center centerbackground-size:cover">

</div>