截取字符串一般是用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,否则截取字符串无效。
原文地址是:一章节。
涉及到只是点:。
如对本文有疑问, 点击进行留言回复!!
清除新版Google Chrome浏览器中表单控件(input,button...)默认的黑色边框
荐 20200714——git/mac配置/项目运行步骤/一些报错
antd 菜单组件 使用时报错:Cannot read property ‘isRootMenu‘ of undefined
CSS|div的style=“background-image: url(img/a.bmp)图片显示不出来
硬件仪表盘账号建立指导(一) --WHQL认证测试结果提交账号(一)
cookie的规范Cookie的不可跨域名性或Cookie与域名的关系
网友评论