Multi-Line Text overflow display ellipsis (...) Method

Source: Internet
Author: User

All browsers currently supporttext-overflow:ellipsisThis attribute is used to display the ellipsis in a single line of text. However, this attribute does not support multiple lines of text. Is there a way to achieve the same effect on multiple texts?

-WebKit-line-clamp

WebKit supports-webkit-line-clampIt is actually a WebKit-specific unsupported property, that is to say, this property is not a part of the standard, may be used inside WebKit, or is discarded. But since it was discovered and can be used, why not try it ~ O (partition _ partition) O

p {    overflow : hidden;    text-overflow: ellipsis;    display: -webkit-box;    -webkit-line-clamp: 2;    -webkit-box-orient: vertical;}

Demo: http://jsfiddle.net/Cople/maB8f/

-O-ellipsis-lastline

Since opera 10.60, the text-overflow attribute has a name-o-ellipsis-lastline. The effect after the application is like the name, and the ellipsis is added to the last line of the text. This method is much easier than the upstairs method, but unfortunately it is not within the standard )//

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

Demo: http://jsfiddle.net/Cople/ash5v/

Jquery

Besides the private attributes of various browsers, is there any cross-browser solution? Of course it is implemented through JS! (Delete 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)(\.\.\.)?$/, "..."));    };});

Demo: http://jsfiddle.net/Cople/DrML4/5/

Htmljquery tutorial

In addition to the reprinted content, this article is an original article. Reprinted Please note: Article Reprinted from: Xiaoying Zhi (http://c7sky.com /)

Multi-Line Text overflow display ellipsis (...) Method

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.