Two common solutions to html text overflow display ellipsis characters

Two common solutions to html text overflow display ellipsis characters

Method 1: Use CSS overflow omission to solve

The solution is as follows:

CSS code:

display: -webkit-box;
            display: -moz-box;
            white-space: pre-wrap;
            word-wrap: break-word;
            overflow: hidden;
            text-overflow: ellipsis;
            -webkit-box-orient: vertical;
            -webkit-line-clamp:2; /*Display number of lines*/

Method 2: Use jQuery to intercept and replace text content

The solution is as follows:

js code:

$(".text").each(function() {
    if ($(this).text().length > 20) {//Requires the number of words to be greater than 20 before replacing the number of words$(this).html($(this).text().replace(/\s+/g, "").substr(0, 80) + "...")
        //Start replacing from 0 to 80, and replace the remaining text content with "..."
    }
})

The above two methods can be applied to the class name of the text content.

Summarize

The above are two common solutions to the problem of ellipsis characters displayed when HTML text overflows. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

<<:  MySQL database JDBC programming (Java connects to MySQL)

>>:  What is JavaScript anti-shake and throttling

Recommend

Several scenarios for using the Nginx Rewrite module

Application scenario 1: Domain name-based redirec...

Two ways to connect WeChat mini program to Tencent Maps

I've been writing a WeChat applet recently an...

Detailed explanation of fetch network request encapsulation example

export default ({ url, method = 'GET', da...

MySQL slow query method and example

1. Introduction By enabling the slow query log, M...

Why can't I see the access interface for Docker Tomcat?

Question: Is the origin server unable to find a r...

CSS scroll bar style modification code

CSS scroll bar style modification code .scroll::-...

Example code for drawing double arrows in CSS common styles

1. Multiple calls to single arrow Once a single a...

MYSQL database GTID realizes master-slave replication (super convenient)

1. Add Maria source vi /etc/yum.repos.d/MariaDB.r...

A brief discussion on the synchronization solution between MySQL and redis cache

Table of contents 1. Solution 1 (UDF) Demo Case 2...