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

JavaScript to achieve time range effect

This article shares the specific code for JavaScr...

How to use the vue timeline component

This article example shares the specific implemen...

vue uses Ele.me UI to imitate the filtering function of teambition

Table of contents Problem Description The general...

How to turn a jar package into a docker container

How to turn a jar package into a docker container...

This article will help you understand the life cycle in Vue

Table of contents 1. beforeCreate & created 2...

JavaScript imitates Taobao magnifying glass effect

This article shares the specific code for JavaScr...

How to change the CentOS server time to Beijing time

1. I purchased a VPS and CentOS system, and found...

Example of pre-rendering method for Vue single page application

Table of contents Preface vue-cli 2.0 version vue...

CSS3 mouse hover transition zoom effect

The following is a picture mouse hover zoom effec...

Some small methods commonly used in html pages

Add in the <Head> tag <meta http-equiv=&q...

How to set up Windows Server 2019 (with pictures and text)

1. Windows Server 2019 Installation Install Windo...

Bundling non-JavaScript static resources details

Table of contents 1. Custom import in packaging t...

The new version of Chrome browser settings allows cross-domain implementation

Preface Currently, the front-end solves cross-dom...