css to implement ellipses when text overflows

王林
Release: 2020-06-04 16:39:33
forward
2717 people have browsed it

css to implement ellipses when text overflows

1. Single-line text overflow

If you want to realize the overflow of a single line of text and display the ellipsis, you can use the text-overflow:ellipsis attribute. Of course, you also need Add width attribute to be compatible with partial browsing.

Implementation method:

overflow: hidden; text-overflow:ellipsis; white-space: nowrap;
Copy after login

The effect is as shown:

css to implement ellipses when text overflows

##2. Overflow of multi-line text

Implementation method:

display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden;
Copy after login
The effect is as shown:

css to implement ellipses when text overflows##Applicable scope:

Due to the use of WebKit CSS extended attributes, this method is suitable for WebKit browsers and mobile terminals.

Note:

-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 be combined with other WebKit properties. Commonly combined attributes: display: -webkit-box; Attributes that must be combined to display the object as a flexible box model.

-webkit-box-orient must be combined with the attribute to set or retrieve the arrangement of the child elements of the flex box object.

Implementation method:

css to implement ellipses when text overflowsThe effect is as shown:

css to implement ellipses when text overflowsApplicable scope:

This method has a wide range of applications, but ellipses will also appear when the text does not exceed the line. This method can be optimized with js.

Note:

Set height to an integer multiple of line-height to prevent excess text from being exposed.

Add a gradient background to p::after to prevent only half of the text from being displayed.

Since ie6-7 does not display content content, you need to add tags to be compatible with ie6-7 (such as:...); to be compatible with ie8, you need to replace ::after with :after .

Recommended tutorial:

css quick start

The above is the detailed content of css to implement ellipses when text overflows. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
css
source:大前端
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!