时间:2021-07-01 10:21:17 帮助过:69人阅读
代码实例如下:
<!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
以上就是使用纯CSS3截取字符串的详细内容,更多请关注Gxl网其它相关文章!