The CSS resolves the text number of words beyond the display ellipsis ... Method (Single-line, multi-text)

Source: Internet
Author: User
If the implementation of a single line of text overflow display ellipsis students should know to use the Text-overflow:ellipsis attribute, of course, also need to add width of the genus to be compatible with some of the browsing.

Implementation method:

Overflow:hidden;text-overflow:ellipsis;white-space:nowrap;

Effect

But this property only supports a single line of text overflow display ellipsis, if we want to implement multi-line text overflow display ellipsis it.

The next step is to say that multiple lines of text overflow display ellipses, as follows.

Implementation method:

Display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:3;overflow:hidden;

Effect

Scope of application:
Due to the use of WebKit CSS extension properties, this method is suitable for WebKit browser and mobile side;

Note:

1.-webkit-line-clamp is used to limit the number of lines of text displayed in a block element. To achieve this effect, it needs to combine other WebKit properties. Common binding Properties:

2.display:-webkit-box; You must combine the properties to display the object as an elastic telescopic box model.

3.-webkit-box-orient must combine properties to set or retrieve the arrangement of child elements of a telescopic box object.

Implementation method:

p{position:relative; line-height:20px; max-height:40px;overflow:hidden;} P::after{content: "..."; Position:absolute; bottom:0; Right:0;padding-left:40px;background:-webkit-linear-gradient (left, Transparent, #fff 55%); background:- O-linear-gradient (right, transparent, #fff 55%); background:-moz-linear-gradient (right, transparent, #fff 55%); Background:linear-gradient (to right, transparent, #fff 55%);}

Effect
Scope of application:
This method can be used in a wide range of applications, but the text does not exceed the line of the case will also appear ellipsis, combined with JS optimization of the method.

Note:

1. Set height to an integer multiple of line-height to prevent excess text from revealing.

2. Add a gradient background to P::after to prevent text from appearing in half.

3. Because ie6-7 does not display content contents, it is necessary to add a label compatible with ie6-7 (such as:<span>...<span/>); compatible IE8 need to replace: After replaced by: after.

"Recommended"

1. HTML text control display the number of words beyond the use of ellipsis method

2. Use CSS to resolve the title display the number of words out of the way

3. Online CSS free video tutorial

Related Article

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.