码迷,mamicode.com
首页 > Web开发 > 详细

CSS3截取字符串实例代码

时间:2018-06-02 20:41:48      阅读:239      评论:0      收藏:0      [点我收藏+]

标签:css   charset   content   blank   top   rap   second   col   fir   

截取字符串一般是用js或者后台语言来实现,其实使用CSS也是可以实现此效果的。

代码实例如下:

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.softwhy.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>
<div id="first">蚂蚁部落欢迎您,只有奋斗才会有美好的未来</div> 
<div id="second">蚂蚁部落欢迎您,只有奋斗才会有美好的未来</div> 
</body>
</html>

特别注意的是:不能够省略white-space:nowrap和overflow:hidden,否则截取字符串无效。

 原文地址是:CSS3截取字符串实例代码一章节。

涉及到只是点:CSS3教程

CSS3截取字符串实例代码

标签:css   charset   content   blank   top   rap   second   col   fir   

原文地址:https://www.cnblogs.com/softwhy/p/9126400.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!