How to hide more than a specified row and show expand all

want to achieve the effect in the following figure:

there are multiple tags, each of which is of different length, and they are arranged freely. When more than two lines are arranged, the rest are automatically hidden, and the expand button is displayed at this time.

I know how to hide the rest more than two lines, but how can I tell if these tags have more than two lines?

A line may leave a lot of space because there is not enough space left for the next label to fill. In short, this free arrangement is not good to judge the number of lines by the number of words, and ask for some suggestions!


if the height of each row is controllable, my idea is to determine whether the expand button is displayed by judging the height of two rows. The idea of
is
1, set the height of the parent element to the height of 2 rows, and hide the excess of the child element with overflow:hidden.
2. Control whether the expand button is displayed by determining whether the height of the child element is greater than the height of two rows.
online demo


think of a stupid way to loop out the last tag until the height of the parent element is less than the specified height


first of all, the selection of tags should not be random, but more, so there is not much need for you to align.

secondly, users must be induced to choose a label of 2 words from the point of view of product operation, otherwise users will have to hang up if they enter dozens of words at random.

on this basis, you only need to display two lines of tags, and then control overflow:hidden to display the rest.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3a1eb-2af2f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3a1eb-2af2f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?