Single line and multi-line text overflow are expressed with ellipsis, and multiple lines overflow with ellipsis

Source: Internet
Author: User

Single line and multi-line text overflow are expressed with ellipsis, and multiple lines overflow with ellipsis

Hiding and displaying ellipsis after a single line or multiple lines of text overflows

Recently, I encountered a problem about text overflow hiding and displaying ellipsis.

I have benefited a lot from searching documents and reading some blog posts. I would like to record that:

1. Single Line Text overflow and hiding:

When the text length exceeds the width of a line, the overflow text will be automatically hidden and the last display '... 'Prompt the user.

Implementation Method:

Pure css style:

P {
Text-overflow: ellipsis; // required
White-space: nowrap; // required
Overflow: hidden; // required
}

The three css attributes set for the p tag above are mandatory and indispensable:

Text-overflow: defines how to handle text overflow. There are two valid values:

Clip: When the inline content overflows the block container, the overflow part is cut out.
Ellipsis: When the inline content overflows the block container, replace the overflow part (...).
2. Multi-Line Text overflow and hiding:
There are two lines of text. When the second line of text overflows, the text exceeds the limit and '... '

Different from a single line of text, the preceding text-overflow attribute cannot be used here. Here, the webkit kernel browser is used, so it can be used on mobile terminals. Code:

P {
Overflow: hidden; // required
Display:-webkit-box; // required
-Webkit-line-clamp: 2; // required
-Webkit-box-orient: vertical; // required
}
In the above Code:

-Webkit-line-clamp: sets the maximum number of lines displayed in the text.
-Webkit-box-orient: If this parameter is not set, the ellipsis (…) is not displayed (...).

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.