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
The implementation of expanding and collapsing li...
background: 1. There is a notification table in t...
vue+el-upload multiple files dynamic upload, for ...
Table of contents 1. Parent-child component commu...
Developers familiar with Element-UI may have had ...
1. Packaging Vue project Enter the following name...
.imgbox{ width: 1200px; height: 612px; margin-rig...
The following is my judgment based on the data st...
As a commonly used database, MySQL requires a lot...
Problem 1: Baidu Map uses tiled images (the map i...
1. E-Commerce Icons 2. Icon Sweets 2 3. Mobile Ph...
Table of contents 01 Common Faults 1 02 Common Fa...
Doccer Introduction: Docker is a container-relate...
<br />Question: Why is it not recommended to...
1. Pull the redis image docker pull redis 2. Star...