99偷拍视频精品区一区二,口述久久久久久久久久久久,国产精品夫妇激情啪发布,成人永久免费网站在线观看,国产精品高清免费在线,青青草在线观看视频观看,久久久久久国产一区,天天婷婷久久18禁,日韩动漫av在线播放直播

怎么通過CSS樣式實現DIV元素中多行文本超長自動省略號

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

員工經過長期磨合與沉淀,具備了協作精神,得以通過團隊的力量開發出優質的產品。創新互聯公司堅持“專注、創新、易用”的產品理念,因為“專注所以專業、創新互聯網站所以易用所以簡單”。公司專注于為企業提供成都做網站、網站設計、微信公眾號開發、電商網站開發,微信小程序,軟件按需制作等一站式互聯網企業服務。

在CSS中,我們可以通過下面的樣式實現DIV元素中文本超長后自動截斷并以省略號結尾:

代碼如下:


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


text-overflow: ellipsis是實現文本截斷后以省略號結尾的關鍵樣式,但問題是如果添加該樣式則DIV元素內的文本無法自動換行,也就是說該效果只被允許在單行文本上實現。另外,word-break: normal可以防止文字被部分截斷,這個在內容為英文的情況下顯得尤其重要。

要實現多行文本自動截斷以省略號結尾的效果,通常的做法是使用JavaScript腳本。下面這些文章給出了如何通過腳本進行字符串截斷,不過僅限于英文環境。

http://www.barelyfitz.com/projects/truncate/

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

http://www.javascriptbank.com/truncate-html-text.html/en/

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

代碼如下:


<!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屬性的值來指定容器的高度。該樣式的實現在多個不同版本的瀏覽器下測試通過,注意如果你是在IE下查看則需要確保你的文檔模型必須是在標準模式下,即Document Mode必須是Standards。

感謝各位的閱讀,以上就是“怎么通過CSS樣式實現DIV元素中多行文本超長自動省略號”的內容了,經過本文的學習后,相信大家對怎么通過CSS樣式實現DIV元素中多行文本超長自動省略號這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是創新互聯,小編將為大家推送更多相關知識點的文章,歡迎關注!

網站名稱:怎么通過CSS樣式實現DIV元素中多行文本超長自動省略號
當前地址:http://www.yijiale78.com/article42/pcheec.html

成都網站建設公司_創新互聯,為您提供品牌網站設計Google云服務器營銷型網站建設品牌網站建設

廣告

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

微信小程序開發