CSS implements single-line and multi-line text overflow to show ellipsis, and css single-line overflow ellipsis

Source: Internet
Author: User

CSS implements single-line and multi-line text overflow to show ellipsis, and css single-line overflow ellipsis

If you use the ellipsis (ellipsis) for overflow display of a single line of text, you must use the text-overflow: ellipsis attribute. Of course, you must add the width and width to support partial browsing.

Implementation Method:

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

 

Effect:

However, this attribute only supports displaying ellipsis in a single line of text. If we want to display ellipsis in multiple lines of text overflow.

Next, we will focus on displaying ellipsis in multi-line text overflow, as shown below.

 

Implementation Method:

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

 

Effect:

 

 

Applicability:
This method is applicable to WebKit browsers and mobile terminals because WebKit CSS extension attributes are used;

Note:

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:

 

Applicability:
This method is applicable to a wide range of fields, but there will also be ellipsis in the case of text travel not exceeding the limit, you can use js to optimize this method.

Note:

 

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.