Text truncation with CSS Consider the following code to implement the style code for automatic truncation of text: .truncate-text-4 { overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 4; } Use the following HTML snippet for testing: <style> .my-div { width: 300px; margin: 10px auto; background: #ddd; } </style> <div class="my-div truncate-text-4"> How Not To Shuffle - The Knuth Fisher-Yates Algorithm. Written by Mike James. Thursday, February 16, 2017. Sometimes simple algorithms are just wrong. this case shuffling an .... In other words as the array is scanned the element under </div> Operation effect: Text truncation effect achieved through CSS The padding problem Everything works perfectly until I add .my-div { width: 300px; margin: 10px auto; background: #ddd; + padding: 30px; } Current effect The effect now is this: Because Solution When .my-div { width: 300px; margin: 10px auto; background: #ddd; padding: 30px; + line-height: 75px; } Fix it with This method is not suitable for all scenarios, because not all places require such a large line height. Replace padding For example, You can also use .my-div { width: 300px; margin: 10px auto; background: #ddd; - padding: 30px; + border: 30px solid transparent; } Use Not surprisingly, it still has its limitations. That is, when the element itself has its own Separate margins from content container This may be a more universal method, which is to separate the content and margin into two elements, one element is used specifically to implement the margin, and the other element is used to implement text truncation. This is easy to understand, just look at the code: <div className="my-div"> <div className="truncate-text-4"> How Not To Shuffle - The Knuth Fisher-Yates Algorithm. Written by Mike James. Thursday, February 16, 2017. Sometimes simple algorithms are just wrong. In this case shuffling an .... In other words as the array is scanned the element under </div> </div> Our styles can remain the same. Separate margins from content container Related resources overflow:hidden ignoring bottom padding How can I force overflow: hidden to not use up my padding-right space The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. |
<<: Detailed explanation of the basic use of react-navigation6.x routing library
>>: Implementation of Redis master-slave cluster based on Docker
This article describes the Linux user and group c...
Preface In our daily development process, sorting...
When we develop a single-page application, someti...
Preface How to write efficient SQL statements is ...
Table of contents 1. Solution 1 (UDF) Demo Case 2...
Table of contents Hbase installation and configur...
Table of contents 1. Basic Use 2. Working Princip...
Every time I design a web page or a form, I am tr...
Application Scenario In the data table, the appli...
Preface Merging or splitting by specified charact...
How to use the concat function in MySQL: CONCAT(s...
Preface When developing WeChat applets, you often...
The previous article introduced a detailed exampl...
Overview binlog2sql is an open source MySQL Binlo...
Nextcloud is an open source and free private clou...