当前位置:Gxlcms > JavaScript > csstext-overflow属性怎么用

csstext-overflow属性怎么用

时间:2021-07-01 10:21:17 帮助过:46人阅读

css text-overflow属性用于指定当文本溢出包含它的元素时,应该发生什么事情。所有主流浏览器都支持 text-overflow 属性。

css text-overflow属性怎么用?

text-overflow 属性规定当文本溢出包含元素时发生的事情。

语法:

  1. text-overflow: clip|ellipsis|string;

属性值:

● clip:修剪文本。

● ellipsis:显示省略符号来代表被修剪的文本。

● string:使用给定的字符串来代表被修剪的文本。

注释:所有主流浏览器都支持 text-overflow 属性。

css text-overflow属性 示例

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <style>
  6. div.test
  7. {
  8. white-space:nowrap;
  9. width:12em;
  10. overflow:hidden;
  11. border:1px solid #000000;
  12. }
  13. </style>
  14. </head>
  15. <body>
  16. <p>以下 div 容器内的文本无法完全显示,可以看到它被裁剪了。</p>
  17. <p>div 使用 &quot;text-overflow:ellipsis&quot;:</p>
  18. <div class="test" style="text-overflow:ellipsis;">This is some long text that will not fit in the box</div>
  19. <p>div 使用 &quot;text-overflow:clip&quot;:</p>
  20. <div class="test" style="text-overflow:clip;">This is some long text that will not fit in the box</div>
  21. <p>div 使用自定义字符串 &quot;text-overflow: &gt;&gt;&quot;(只在 Firefox 浏览器下有效):</p>
  22. <div class="test" style="text-overflow:'>>';">This is some long text that will not fit in the box</div>
  23. </body>
  24. </html>

效果图:

1.jpg

以上就是css text-overflow属性怎么用的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行