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

MySQL database case sensitivity issue

In MySQL, databases correspond to directories wit...

Why not use UTF-8 encoding in MySQL?

MySQL UTF-8 encoding MySQL has supported UTF-8 si...

HTML table markup tutorial (1): Creating a table

<br />This is a series of tutorials provided...

Docker memory monitoring and stress testing methods

The Docker container that has been running shows ...

How to configure Openbox for Linux desktop (recommended)

This article is part of a special series on the 2...

Introduction to Linux system swap space

Swap space is a common aspect of computing today,...

Pure HTML and CSS to achieve JD carousel effect

The JD carousel was implemented using pure HTML a...

Use of SerialPort module in Node.js

Table of contents Purpose Module Installation Bas...

Example code for converting html table data to Json format

The javascript function for converting <table&g...

Multiple ways to insert SVG into HTML pages

SVG (Scalable Vector Graphics) is an image format...

Example of converting timestamp to Date in MySQL

Preface I encountered a situation at work: In the...