I have a vertical menu in my system which is basically made of HTML ul
/li
with CSS styling (see image below). However I don't want the li
items which are wider than the menu to wrap, I would prefer them to overflow with a horizontal scroll bar at the bottom of the menu. How can I do this in CSS?
If you want to prevent the text from wrapping, you can apply white-space: nowrap; Notice in HTML code example at the top of this article, there are actually two line breaks, one before the line of text and one after, which allow the text to be on its own line (in the code).
The <wbr> element If you know where you want a long string to break, then it is also possible to insert the HTML <wbr> element. This can be useful in cases such as displaying a long URL on a page.
ul { overflow: auto; // allow li's to overflow w/ scroll bar // at the bottom of the menu } li { white-space: nowrap; // stop the wrapping in the first place }
Use white-space:nowrap
. Like so:
li { white-space:nowrap; }
Here's some documentation.
You would also need to give the style the ul:
ul{
width:250px;
overflow:auto;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With