css实现内容超出隐藏效果的方法是,给文本内容添加text-overflow属性,例如【text-overflow:ellipsis】。text-overflow属性指定当文本溢出包含它的n j M W元素应该发生什么。
本文操作环境:windows10系统、css 3、thinkpad t480电脑。
css为我们提供了一个很适合的元素text-overflow,这个属性指定当文本溢出包含它的元素,应该发生什么。
语法:
text-overflow: clip|ellipsis|string;
属性值:
-
clip} F Y X h C I f + 修剪文本。
-
ellipsis 显示省略符号来代表被A z ( ^ V修剪的文本。
-
string 使用给定的字符串来代表被修剪的文本。
举个例子:
<!DOCTYPE html> <html> <head&U \ \ T g R # p Zgt; <mO o V L e h }eta charset="utf-8"> <title></tit4 F \ [ l Yle> <style> div.test { white-space:& = r Anowrap; width:12em; overflow:hidden; border:1px solid #000000; } &lQ U Pt;/style&gY z O [ / 3 ;t; </head> <body> <p>以下 div 容器内的文本无法完全显示,可以看到它被裁剪了。</p> <p>div 使用 "text-overflow:ellipsis":</p> <div class="tex x I [st">This is some long text that will not fit in the box</div> <p>div 使用 "] @ 1 1 x @ q v \;text-overflow:clip":</p> <div class="test">TA P 7 t q z Phis is some long tex= k q % W / $t that will not fit in the box</div> <p>9 M W s P b 4 mdiv 使用自定义字符串 "tex8 [ h i }t-overflX - V oow: >&W { i # 4 u . y %gt;"(只在 Firefox 浏览* Z a ]器下有效):</p> <div class="test">This is some long text that will not fitb y 7 h N = ! { in the box</div> </body> </html>
展示效果:
相关视频分享:css视频教程
以上就是css怎么实现内容超出隐藏效果的详细内容,更多请关注php中文网其它相关s D y l w ? j文章!
声明:本文原创发布php中文网,转载请注明出处,感谢您Q p ( 5的尊重!如有疑问,请联系admin@php.cn处理
原创文章,作者:町子门户,如若转载,请注明出处:https://www.6fzz.com/12215.html