首頁  >  文章  >  web前端  >  css text-overflow屬性怎麼用

css text-overflow屬性怎麼用

青灯夜游
青灯夜游原創
2019-05-29 16:58:393039瀏覽

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

css text-overflow屬性怎麼用

css text-overflow属性怎么用?

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

语法:

text-overflow: clip|ellipsis|string;

属性值:

● clip:修剪文本。        

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

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

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

css text-overflow属性 示例

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<style> 
div.test
{
white-space:nowrap; 
width:12em; 
overflow:hidden; 
border:1px solid #000000;
}
</style>
</head>
<body>
<p>以下 div 容器内的文本无法完全显示,可以看到它被裁剪了。</p>
<p>div 使用 "text-overflow:ellipsis":</p>
<div class="test" style="text-overflow:ellipsis;">This is some long text that will not fit in the box</div>
<p>div 使用 "text-overflow:clip":</p>
<div class="test" style="text-overflow:clip;">This is some long text that will not fit in the box</div>
<p>div 使用自定义字符串 "text-overflow: >>"(只在 Firefox 浏览器下有效):</p>
<div class="test" style="text-overflow:&#39;>>&#39;;">This is some long text that will not fit in the box</div>
</body>
</html>

效果图:

css text-overflow屬性怎麼用

以上是css text-overflow屬性怎麼用的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn