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

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

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
$(function(){
$('.list-toggle').click(function(){
$('.u-list').toggleClass('open');
});
});
.u-list li:nth-child(n+5) {
 display: none;
}

.u-list.open li:nth-child(n+5) {
 display: list-item;
}

Find more questions by tags PHPWeb Development