Description: Limit the number of lines of text displayed in a block element. -webkit-line-clamp is an unsupported WebKit property that does not appear in the CSS draft specification. To achieve this effect, it needs to combine other exotic WebKit properties. Common combination properties:
Today we received an optimization request, requiring the content in the post list to be shortened to 3 lines with '…' ellipsis <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title>cline-clamp</title> <style> .box{ width: 200px; height: 300px; border:1px solid black; } p{ display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 4; /*Set the maximum number of lines for the p element to be 4. The parent element needs to fill in the width to be obvious*/ text-overflow: ellipsis; overflow: hidden; /* autoprefixer: off */ -webkit-box-orient: vertical; /* autoprefixer: on */ /*Because of the code environment, webkit-box-orient is filtered out. This keyword autoprefixer can be exempted from being filtered.*/ word-wrap:break-word; word-break:break-all; } </style> </head> <body> <div class="box"> <p> static: The object follows the normal flow. The top, right, bottom, left, etc. properties will not be applied. relative: The object follows the normal flow, and when it is offset by the top, right, bottom, left properties relative to its position in the normal flow, it does not affect any elements in the normal flow. absolute: The object is out of the normal flow and is absolutely positioned using properties such as top, right, bottom, and left. </p> </div> </body> </html> The effect is as follows: If the text in your tag is in English, it will not wrap automatically, so you need to add the following code to make it wrap automatically: word-wrap:break-word; word-break:break-all; Of course, you can also use the plug-in clamp.js This concludes this article on how to use the CSS3 property line-clamp to control the number of text lines. For more information about how to use the CSS3 line-clamp to control the number of lines, please search previous articles on 123WORDPRESS.COM or continue browsing the related articles below. We hope that everyone will support 123WORDPRESS.COM in the future! |
<<: Question about custom attributes of html tags
>>: Detailed explanation of Vue plugin
The latest Insider version of Visual Studio Code ...
uniapp code <template> <view> <ima...
If you want the application service in the Docker...
Hello everyone, I am Liang Xu. When using Linux, ...
Preface Every developer who comes into contact wi...
1. First find the Data file on the migration serv...
1. Introduction to Macvlan Before the emergence o...
1. Introduction to Compose Compose is a tool for ...
I recently used a Mac system and was preparing to...
Installation Steps 1. Create a virtual machine 2....
1. Create a SpringBooot project and package it in...
1. Introduction to mysqlbackup mysqlbackup is the...
Table of contents Preface Optional Chaining Nulli...
In Google Chrome, after successful login, Google ...
1. Install Docker yum -y install docker-io The &q...