首页 > 开发 > CSS > 正文

CSS3截取字符串实例代码【推荐】

2024-07-11 08:42:08
字体:
来源:转载
供稿:网友

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

代码实例如下:

<!DOCTYPE html><html><head><meta charset=" utf-8"><meta name="author" content="https://www.VeVb.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截取字符串实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对武林网网站的支持!

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表