Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML CSS LI Wrapping

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?

like image 364
Craig Avatar asked Nov 17 '08 22:11

Craig


People also ask

How do I stop text wrapping 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).

How do you break a long text in CSS?

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.


3 Answers

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 } 
like image 158
Owen Avatar answered Sep 28 '22 06:09

Owen


Use white-space:nowrap. Like so:

li {   white-space:nowrap; } 

Here's some documentation.

like image 34
sblundy Avatar answered Sep 28 '22 08:09

sblundy


You would also need to give the style the ul:

ul{
 width:250px;
 overflow:auto;
}
like image 44
slashnick Avatar answered Sep 28 '22 07:09

slashnick