As far as I know, there is no CSS-based workaround for this. However, you can use jQuery to solve it.
I did a little test so you can see:
http://sotkra.com/stackoverflow/cssdilemma/cssdilemma.html
The first example has 6 or so li that are larger than the width of the container div, which means you don't need a scroll bar.
The second example has 8-9 li that DO exceed the width of the div container, which means you need a scroll bar.
Basically, you use jQuery to count the number of li inside your div using size (). If they exceed the number X, in my example case 6 (the limit before scrolling is needed), then the class is added to ul to expand its width (longer), so there is no line break and horizontal scrollbar there.
It also adds another class (.taller) that increases the height to accommodate the scrollbar itself.
Greetings G.Campos
source share