horizontal scrolling only!

落花浮王杯 提交于 2019-12-05 18:06:17

As far as I know, there's no CSS-based workaround for this. However, you can use Jquery to solve it.

I made a little test for you to see:

http://sotkra.com/stackoverflow/cssdilemma/cssdilemma.html

The first example has 6 or so li's which exceed the width of the container div which means you DON'T need a scrollbar.

The second example has 8-9 li's which DO exceed the width of the container div which means you DO NEED a scrollbar.

Basically, you use Jquery to count the number of li's inside your div using size(). If they exceed X number, in my example's case 6 (the limit before scroll is needed), then a class is added to the ul to extend its width (.longer) so that there's no line break and the horizontal scrollbar appears.

It also adds another class (.taller) that increases the height to accomodate the scrollbar itself.

Cheers G.Campos

You might be able to use the white-space property to prevent wrapping. It's hard to know if it's applicable in your case without more code.

For your div, try:

white-space: nowrap;

You need to put one massive horizontal div inside the parent div with overflow: auto; This will allow the

  • to float left without wrapping to the next line, and it will only scroll when the boundary of the parent div is crossed.
  • 易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
    该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!