欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

怎么通過CSS樣式實(shí)現(xiàn)DIV元素中多行文本超長自動省略號-創(chuàng)新互聯(lián)

這篇文章主要講解了“怎么通過CSS樣式實(shí)現(xiàn)DIV元素中多行文本超長自動省略號”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“怎么通過CSS樣式實(shí)現(xiàn)DIV元素中多行文本超長自動省略號”吧!

專注于為中小企業(yè)提供網(wǎng)站制作、成都網(wǎng)站制作服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)昌邑免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動了上1000+企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。

在CSS中,我們可以通過下面的樣式實(shí)現(xiàn)DIV元素中文本超長后自動截?cái)嗖⒁允÷蕴柦Y(jié)尾:



代碼如下:

overflow: hidden;
word-break: normal;
text-overflow: ellipsis;


text-overflow: ellipsis是實(shí)現(xiàn)文本截?cái)嗪笠允÷蕴柦Y(jié)尾的關(guān)鍵樣式,但問題是如果添加該樣式則DIV元素內(nèi)的文本無法自動換行,也就是說該效果只被允許在單行文本上實(shí)現(xiàn)。另外,word-break: normal可以防止文字被部分截?cái)啵@個(gè)在內(nèi)容為英文的情況下顯得尤其重要。

要實(shí)現(xiàn)多行文本自動截?cái)嘁允÷蕴柦Y(jié)尾的效果,通常的做法是使用JavaScript腳本。下面這些文章給出了如何通過腳本進(jìn)行字符串截?cái)啵贿^僅限于英文環(huán)境。

/tupian/20230522/

http://www.javascriptsource.com/miscellaneous/truncate-text.html

/tupian/20230522/

使用純CSS樣式來實(shí)現(xiàn)該效果則會稍微有些麻煩,你需要懂得如何在CSS中進(jìn)行hack。這里是一個(gè)可以在多個(gè)通用瀏覽器中實(shí)現(xiàn)該效果的例子:



代碼如下:

<!DOCTYPE HTML>
<html>
<head>
<style>
html, body, p { margin: 0; padding: 0; font-family: sans-serif;}
.ellipsis {
overflow: hidden;
height: 200px;
line-height: 25px;
margin: 20px;
border: 5px solid #AAA; }
.ellipsis:before {
content:"";
float: left;
width: 5px; height: 200px; }
.ellipsis > *:first-child {
float: right;
width: 100%;
margin-left: -5px; }
.ellipsis:after {
content: "\02026";
box-sizing: content-box;
-webkit-box-sizing: content-box;
-moz-box-sizing: content-box;
float: right; position: relative;
top: -25px; left: 100%;
width: 3em; margin-left: -3em;
padding-right: 5px;
text-align: right;
background: -webkit-gradient(linear, left top, right top,
from(rgba(255, 255, 255, 0)), to(white), color-stop(50%, white));
background: -moz-linear-gradient(to right, rgba(255, 255, 255, 0), white 50%, white);
background: -o-linear-gradient(to right, rgba(255, 255, 255, 0), white 50%, white);
background: -ms-linear-gradient(to right, rgba(255, 255, 255, 0), white 50%, white);
background: linear-gradient(to right, rgba(255, 255, 255, 0), white 50%, white); }
</style>
</head>
<body>
<div class="ellipsis"><div>
<p>Call me Ishmael. Some years ago &ndash; never mind how long precisely &ndash; having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world. It is a way I have of driving off the spleen, and regulating the circulation. Whenever I find myself growing grim about the mouth; whenever it is a damp, drizzly November in my soul; whenever I find myself involuntarily pausing before coffin warehouses, and bringing up the rear of every funeral I meet; and especially whenever my hypos get such an upper hand of me, that it requires a strong moral principle to prevent me from deliberately stepping into the street, and methodically knocking people's hats off &ndash; then, I account it high time to get to sea as soon as I can.</p>
</div></div>
</body>
</html>


通過修改.ellipsis和.ellipsis:before樣式中height屬性的值來指定容器的高度。該樣式的實(shí)現(xiàn)在多個(gè)不同版本的瀏覽器下測試通過,注意如果你是在IE下查看則需要確保你的文檔模型必須是在標(biāo)準(zhǔn)模式下,即Document Mode必須是Standards。

感謝各位的閱讀,以上就是“怎么通過CSS樣式實(shí)現(xiàn)DIV元素中多行文本超長自動省略號”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對怎么通過CSS樣式實(shí)現(xiàn)DIV元素中多行文本超長自動省略號這一問題有了更深刻的體會,具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是創(chuàng)新互聯(lián)網(wǎng)站建設(shè)公司,,小編將為大家推送更多相關(guān)知識點(diǎn)的文章,歡迎關(guān)注!

標(biāo)題名稱:怎么通過CSS樣式實(shí)現(xiàn)DIV元素中多行文本超長自動省略號-創(chuàng)新互聯(lián)
本文來源:http://chinadenli.net/article34/shepe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供關(guān)鍵詞優(yōu)化網(wǎng)站設(shè)計(jì)公司網(wǎng)站建設(shè)網(wǎng)站收錄虛擬主機(jī)網(wǎng)站排名

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

綿陽服務(wù)器托管