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
Table of contents Overview Blob Blob in Action Bl...
If you are not committed to becoming an artist, t...
1.This points to 1. Who calls whom? example: func...
In Linux, everything is a file, so the Android sy...
1. Case Take all employees who are not the head o...
Table of contents Preface 1. Basic usage of liste...
1. Delete the original mariadb, otherwise mysql c...
Table of contents Why use Docker? Docker installa...
Demand background Part of the data in the busines...
1. First, the pure HTML file must have an entry i...
1. Form <form id="" name=""...
Flex Layout Flex is the abbreviation of Flexible ...
As a front-end monkey, whether it is during an in...
Install lua wget http://luajit.org/download/LuaJI...
Table of contents Index Model B+Tree Index select...