

截取字符串一般是用js或者后台语言来实现,其实使用CSS也是可以实现此效果的。
代码实例如下:
<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.gxlcms.com/" />
<title>CSS教程-脚本之家</title>
<style type="text/css">
#first{
width:120px;
height:30px;
background-color:#F30;
overflow:hidden;
text-overflow:clip;
white-space:nowrap;
}
#second{
width:120px;
height:30px;
background-color:#F30;
overflow:hidden;
text-overflow:ellipsis;
white-space:nowrap;
margin-top:10px;
}
</style>
</head>
<body>
<p id="first">脚本之家欢迎您,只有奋斗才会有美好的未来</p>
<p id="second">脚本之家欢迎您,只有奋斗才会有美好的未来</p>
</body>
</html>特别注意的是:不能够省略white-space:nowrap和overflow:hidden,否则截取字符串无效。
