How to display opredelennoe number of words, depending on the size?

In the template php cycle derived categories of goods. They are displayed on the website here in this small unit:

The red box I've highlighted the place designated for these subcategories, the outside should not be. But overflow:hidden - it looks scary.

To prohibit the display of more than n number of categories in php is also impossible, because there are categories with small names, and they will fit more than 6 pieces. And there are long names, for example: "Foreign medical equipment", then on the strength of these 2 pieces will be located.

How it can be implemented? Thank you.
June 5th 19 at 21:14
1 answer
June 5th 19 at 21:16
.u-list li:nth-child(n+5) {
 display: none;
} li:nth-child(n+5) {
 display: list-item;

Find more questions by tags PHPWeb Development