怎么用css截取字符?
問題描述
怎么用css截取字符?
問題解答
回答1:怎么用css截取字符?-PHP中文網(wǎng)問答-怎么用css截取字符?-PHP中文網(wǎng)問答
圍觀一下哦,學(xué)習(xí)一下。
回答2:方法一:
<p style="width:300px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;"> 任意長度的字符串 </p>
說明:優(yōu)點(diǎn)是內(nèi)容可以為任何HTML元素,包括超鏈接和圖片等,在IE6中還會(huì)在結(jié)尾自動(dòng)顯示省略號(hào)。缺點(diǎn)是必須指定寬度數(shù)值,并且寬度不能是百分?jǐn)?shù),否則在IE中會(huì)被認(rèn)為是字符總長的百分比。
方法二:
<input type="text" style="width:100%; cursor:default; border-width:0; border-style:none; background-color:transparent;" value="任意長度的字符串" readonly/>
說明:優(yōu)點(diǎn)是寬度可以設(shè)為百分?jǐn)?shù)。但缺點(diǎn)是內(nèi)容只能為純文本,不能有超鏈接等內(nèi)容。
CSS是實(shí)現(xiàn)文字自動(dòng)截?cái)啵a如下:
p.test{ width:200px; height:14px; overflow:hidden; white-space:nowrap; text-overflow:ellipsis; text-overflow: ellipsis;/* IE/Safari */ -ms-text-overflow: ellipsis; -o-text-overflow: ellipsis;/* Opera */ -moz-binding: url("ellipsis.xml#ellipsis");/*FireFox*/}
用text-overflow的最佳場(chǎng)所不是文章的行文,而是用以單行顯示的標(biāo)題或摘要的列表。
相關(guān)文章:
1. boot2docker無法啟動(dòng)2. 關(guān)于docker下的nginx壓力測(cè)試3. java - SSH框架中寫分頁時(shí)service層中不能注入分頁類4. docker安裝后出現(xiàn)Cannot connect to the Docker daemon.5. mac里的docker如何命令行開啟呢?6. node.js - antdesign怎么集合react-redux對(duì)input控件進(jìn)行初始化賦值7. 為什么我ping不通我的docker容器呢???8. 老師,按tab鍵不起作用怎么回事9. docker鏡像push報(bào)錯(cuò)10. dockerfile - 為什么docker容器啟動(dòng)不了?

網(wǎng)公網(wǎng)安備