最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

通過(guò)純CSS樣式實(shí)現(xiàn)DIV元素中多行文本超長(zhǎng)自動(dòng)省略號(hào)

  發(fā)布時(shí)間:2014-05-05 15:45:46   作者:佚名   我要評(píng)論
可以通過(guò)css樣式實(shí)現(xiàn)DIV元素中文本超長(zhǎng)后自動(dòng)截?cái)嗖⒁允÷蕴?hào)結(jié)尾,一般情況下都是使用javascript,其實(shí)使用純CSS樣式也可以做到
在CSS中,我們可以通過(guò)下面的樣式實(shí)現(xiàn)DIV元素中文本超長(zhǎng)后自動(dòng)截?cái)嗖⒁允÷蕴?hào)結(jié)尾:

復(fù)制代碼
代碼如下:

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

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

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

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

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

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

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

復(fù)制代碼
代碼如下:

<!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>

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

相關(guān)文章

  • css高級(jí)應(yīng)用三種方法實(shí)現(xiàn)多行省略的示例代碼

    這篇文章主要介紹了css高級(jí)應(yīng)用三種方法實(shí)現(xiàn)多行省略的示例代碼的相關(guān)資料,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2019-04-15
  • css多行文本溢出時(shí)出現(xiàn)省略號(hào)的示例

    這篇文章主要介紹了css多行文本溢出時(shí)出現(xiàn)省略號(hào)的示例的相關(guān)資料,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-06-13
  • 純CSS定制文本省略的方法大全

    本篇文章主要介紹了純CSS定制文本省略的方法大全,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-08-16
  • 純 CSS 自定義多行省略的問(wèn)題(從原理到實(shí)現(xiàn))

    這篇文章主要介紹了純 CSS 自定義多行省略的問(wèn)題(從原理到實(shí)現(xiàn)),本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-11-08

最新評(píng)論

苍山县| 习水县| 元谋县| 永福县| 建昌县| 荔波县| 枣阳市| 德江县| 柳河县| 沽源县| 罗平县| 苍山县| 东明县| 颍上县| 景谷| 樟树市| 汾阳市| 普洱| 阿勒泰市| 镇原县| 纳雍县| 新兴县| 古蔺县| 铜梁县| 丽江市| 巴林左旗| 吉安市| 武汉市| 上虞市| 来凤县| 盐源县| 望谟县| 屯昌县| 阿克苏市| 康平县| 遵义市| 长海县| 固阳县| 贵德县| 泊头市| 墨江|