Text overflow ellipsis ......

Source: Internet
Author: User

p { overflow: hidden; white-space: normal; height: 3em;  text-overflow: ellipsis; }

In addition to the CSS attribute, it is implemented through JS (by deleting the end characters one by one from the back to the front until the height of the element is smaller than the height of the parent element)

$(".figcaption").each(function(i){    var divH = $(this).height();    var $p = $("p", $(this)).eq(0);    while ($p.outerHeight() > divH) {        $p.text($p.text().replace(/(\s)*([a-zA-Z0-9]+|\W)(\.\.\.)?$/, "..."));    };});

 

 

Instance:

<Div id = "Fos">
<P> lorem ipsum dolor sit Amet, consectetur adipiscing elit. proin nisi ligula, dapibus A volutpat sit Amet, Mattis et DUI. nunc porttitor accumsan orci ID luctus. phasellus ipsum metus, tincidunt non rhoncus ID, dictum a lectus. NAM sed ipsum A Lacus sodales eleifend. vestibulum lorem Felis, rhoncus elementum vestibulum eget, dictum ut Velit. nullam venenatis, elit in suscipit imperdiet, orci Purus posuere mauris, Quis adipiscing ipsum urna AC quam. </P>
</Div>

 

VaR P = $ ('# Fos p ');
VaR divl = $ ('# Fos'). Height ();
While ($ (P). outerheight ()> divl ){
$ (P). Text (function (index, text ){
Return text. Replace (/\ W * \ s (\ s) * $ /,'...');
});
}

 
http://c7sky.com/text-overflow-ellipsis-on-multiline-text.html
http://jsfiddle.net/MPkSF/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.