The HTML code for intercepting text beyond multiple lines is as follows: HTML: Copy code The code is as follows:<div class="sytm-text-1"> <p> 123WORDPRESS.COM Website: https://www.jb51.net </p> </div> <div class="sytm-text-2"> <p> 123WORDPRESS.COM Website: https://www.jb51.net </p> </div> CSS: Copy code The code is as follows:.sytm-text-1 { color: #FFF; background: #000; width: 410px; height: 22px; } .sytm-text-2 { color: #FFF; background: #000; width: 410px; height: 44px; } p { line-height: 22px; } JS (import jQuery): Copy code The code is as follows:$("div[class*='sytm-text']").each(function(e){ var divHeight = $(this).height(); var $p = $("p", $(this)).eq(0); while ($p.outerHeight() > divHeight) { $p.text($p.text().replace(/(\s)*([a-zA-Z0-9]+|\W)(\.\.\.)?$/, "...")); }; }); From the above code, we can find that the main principle of achieving this effect is to compare the height of the child container (p) with that of the parent container (div) and perform character interception according to the regular expression until the two are equal. Therefore, the key to controlling the number of intercepted lines naturally lies in the div height. |
<<: PNG Alpha Transparency in IE6 (Complete Collection)
>>: Detailed explanation of CSS float property
CSS has two pseudo-classes that are not commonly ...
Preface This article mainly introduces the releva...
<br /> English original: http://desktoppub.a...
Not only does it reduce the cost of website develo...
Browser compatibility is the most important part ...
As shown below: update table1 as z left join tabl...
Table of contents 1. Introduction 1. What is an i...
The operating environment of this tutorial: Windo...
The role of virtual DOM First of all, we need to ...
Friends who have some basic knowledge of SQL must...
Table of contents Multi-table join query Inner Jo...
This article shares the shell script of mysql5.6....
Table of contents 1. Use object to create an obje...
Install MySQL database a) Download the MySQL sour...
MySQL provides two different versions for differe...