2

If I have an unordered list with a number of items, and a max height set on this list with the ul set to display: inline-block (or floated). Then the scrollbar seems to take up the space "inside" the list forcing text to wrap around.

How can I avoid this? I don't mind if the scrollbar makes the list wider, I just want the list to take up its natural space.

http://jsbin.com/AzeBuHU/2/edit?html,css,output

Thanks

Josh Crozier
  • 233,099
  • 56
  • 391
  • 304
hcharge
  • 1,216
  • 2
  • 24
  • 43

3 Answers3

0

overflow-y: scroll; for UL seems to be a fix, but you'll have the scrollbar everytime, even for few items minor to UL height.

Demo

EdenSource
  • 3,387
  • 16
  • 29
  • hmm yeah that's not going to be ideal as my list will probably be shorter than this most of the time and the scrollbar is in a worst case scenario, sorry! – hcharge Oct 09 '13 at 16:09
0

Add this in the CSS. That will prevent the list items from wrapping, and add extra space for the scrollbar.

li {
    padding-right:20px; 
    white-space:nowrap;
}
andi
  • 6,442
  • 1
  • 18
  • 43
-2

Do not give max-height, as it will now take more height than that. You can give ,

height:auto;

Otherwise you can try

overflow:visible;

This will show scrollbars whenever data is more.

Kishori
  • 1,065
  • 6
  • 12
  • No I need a max-height... As I only want to show upto a certain amount of items – hcharge Oct 09 '13 at 16:01
  • No, an element with `height:auto` and no `max-height` will of course _not_ show a vertical scrollbar … – CBroe Oct 09 '13 at 16:01