I have horizontal list:
<ul>
<li><div>long text 1</div></li>
<li><div>long text 2</div></li>
<li><div>long text 3</div></li>
<li><div>long text 4</div></li>
</ul>
with:
ul > li {
display: inline-block;
}
How can I prevent wrapping <li>
to a new line?
I need truncate long text in last visible <li>
, but not wrap the whole <li>
with long text on new line
2
Answers
If the number of elements is always static, it can be accomplished using only CSS, but if it’s dynamic, you’ll have to introduce some JavaScript.
HTML:
CSS (
flexbox
+media queries
):General JavaScript for dynamic number of list items: