平時在寫頁面過程中,相信大家都遇到過文本顯示多行后用省略號代替的問題,來看看代碼:
p{display: -webkit-box;overflow: hidden;text-overflow: ellipsis;-webkit-line-clamp:12;//表示顯示12行之后用省略號代替-webkit-box-orient:vertical; }
可以看到,上面的屬性是帶了-webkit-前綴的,那如果要適應ie的話,能不能在前面加-ms-的前綴呢?
答案是不能,本人親自測了一下,表示根本沒有任何效果;所以找別的辦法吧,就是判斷當前p標簽里面的文字個數,截取到想顯示的到的文字,之后的用“...”表示,來看看代碼
?
<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><title></title><style>.r-advInfo-itemText{padding: 25px 20px;background: pink;color: #000;border-radius: 40px;width: 200px;}.r-advInfo-item p {margin-top: 10px;font-size: 14px;color: #000;line-height: 24px;margin-top:20px;}</style> </head> <body> <div class="r-advInfo-itemText"><p id="qfr"></p> </div> <script>LimitNumber('只顯示20個文字只顯示20個文字只顯示20個文字只顯示20個文字只顯示20個文字只顯示20個文字只顯示20個文字只顯示20個文字只顯示20個文字只顯示20個文字只顯示20個文字只顯示20個文字','qfr',20);/*用js限制字數,超出部分以省略號...顯示*/function LimitNumber(txt,idName,num) {var str = txt;str = str.substr(0,num) + '...' ;var id=document.getElementById(idName);id.innerText=str;}</script> </body> <html>
以上就可以解決ie下的問題了,拿走不謝!