?
This document uses PHP Chinese website manual Release
text-overflow:clip | ellipsis
默認(rèn)值:clip
適用于:塊級容器元素
繼承性:無
動畫性:否
計算值:指定值
clip:當(dāng)內(nèi)聯(lián)內(nèi)容溢出塊容器時,將溢出部分裁切掉。
ellipsis:當(dāng)內(nèi)聯(lián)內(nèi)容溢出塊容器時,將溢出部分替換為(...)。
非visible
時,定義內(nèi)聯(lián)內(nèi)容溢出其塊容器是否截斷或者添加(...)及自定義字符
要使得 <' text-overflow '> 屬性生效,塊容器必須顯式定義 <' overflow '> 為非visible
值,同時顯式或者隱式的定義 <' width '> 為非auto
值, <' white-space '> 為nowrap
值。
用代碼來解釋這段話:
case 1:
<style> .demo p{overflow:hidden;width:200px;white-space:nowrap;text-overflow:ellipsis;} </style> <div class="demo"> <p>這是一句非常非常長的話,被用來做text-overflow屬性測試。</p> </div>
case 1,我們將text-overflow生效必備的3個屬性: <' overflow '> , <' width '> 和 <' white-space '> 都直接定義在了內(nèi)聯(lián)內(nèi)容的父級塊容器上
case 2:
<style>
.demo{width:200px;white-space:nowrap;}
.demo p{overflow:hidden;text-overflow:ellipsis;}
</style>
<div class="demo">
<p>這是一句非常非常長的話,被用來做text-overflow屬性測試。</p>
</div>
case 2,我們將 <' width '> 和 <' white-space '> 定義在了更外層的塊容器上,但case 1和case 2的效果是一樣的。因為這2個屬性可以被繼承
對應(yīng)的腳本特性為textOverflow。
Values | IE | Firefox | Chrome | Safari | Opera | iOS Safari | Android Browser | Android Chrome |
---|---|---|---|---|---|---|---|---|
Basic Support | 6.0+ | 2.0-6.0 | 4.0+ | 6.0+ | 15.0+ | 6.0+ | 2.1+ | 18.0+ |
7.0+ |
<!DOCTYPE html> <html lang="zh-cmn-Hans"> <head> <meta charset="utf-8" /> <title>text-overflow_CSS參考手冊_web前端開發(fā)參考手冊系列</title> <meta name="author" content="Joy Du(飄零霧雨), dooyoe@gmail.com, www.doyoe.com" /> <style> .test li{margin-top:10px;} .test .clip p{overflow:hidden;width:200px;white-space:nowrap;text-overflow:clip;} .test .ellipsis p{overflow:hidden;width:200px;white-space:nowrap;text-overflow:ellipsis;} </style> </head> <body> <ul class="test"> <li class="clip"> <strong>clip: 直接將溢出的文字裁剪</strong> <p>測試用文字測試用文字測試用文字測試用文字測試用文字測試用文字</p> </li> <li class="ellipsis"> <strong>ellipsis: 將溢出的文字顯示省略標(biāo)記(...)</strong> <p>測試用文字測試用文字測試用文字測試用文字測試用文字測試用文字</p> </li> </ul> </body> </html>
點擊 "運行實例" 按鈕查看在線實例