

代码实例如下:
<!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">QWEQWEQWEQWE</p>
<p id="second">QWEQWEQWEQWE</p>
</body>
</html>特别注意的是:不能够省略white-space:nowrap和overflow:hidden,否则截取字符串无效。
相信看了本文案例你已经掌握了方法,更多精彩请关注Gxl网其它相关文章!
推荐阅读:
小程序开发做出弹出菜单功能(附代码)
webpack升级到4.0版本并且安装webpack-cli
