Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot get horizontally-listed ul to overflow horizontally (and scroll)

I'm trying to get an unordered list to be listed out horizontally (accomplished with float:left), but it refuses to overflow horizontally. Instead, it automatically overflows in the next line (furthermore, even with overflow-y:none, it creates a vertical scrollbar automatically. Any ideas?

<style type="text/css">
    ul {
        height:15px;
        width:400px;
        overflow-y:none;
        overflow-x:auto;
    }

    li {
        float:left;
    }

</style>

<body>
    <div>
        <ul id="someList">
            <li>element 1</li>
            <li>element 2</li>
            <li>element 3</li>
            <li>element 4</li>
            <li>element 5</li>
            <li>element 6</li>
            <li>element 7</li>
        </ul>
    </div>
</body>
like image 315
achow Avatar asked Jun 28 '11 22:06

achow


People also ask

How do I make my overflow scroll horizontal?

Set the overflow-y: hidden; and overflow-x: auto; that will automatically hide the vertical scroll bar and present only the horizontal scrollbar. The white-space: nowrap; property is used to wrap text in a single line. Here the scroll div will be horizontally scrollable.

How do I fix the horizontal scroll bar?

The easy fix is to use width: 100% instead. Percentages don't include the width of the scrollbar, so will automatically fit. If you can't do that, or you're setting the width on another element, add overflow-x: hidden or overflow: hidden to the surrounding element to prevent the scrollbar.

Why does overflow hidden not work?

It is because you are using position absolute. You cannot use position absolute with overflow hidden, because position absolute moves the targeted element out of context with the document structure.

How do I make a horizontal scrolling page?

First we will create a content blocks and put them under two layers of wrapper. Then we'll rotate the outer wrapper so that the top side is on the left and the bottom is on the right. This way we turn the vertical scroll into horizontal one. Then we rotate the inner wrapper back so the content is in the right position.


1 Answers

If I understand correctly, this should be it:

http://jsfiddle.net/Uyc8d/

I've switched to using display: inline-block (instead of float: left), and I'm using white-space: nowrap to prevent wrapping.

ul {
    width: 400px;
    overflow-x: scroll;
    background: #ccc;
    white-space: nowrap;
}

li {
    display: inline-block;

    /* if you need ie7 support */
    *display: inline;
    zoom: 1;
}
like image 163
thirtydot Avatar answered Sep 21 '22 05:09

thirtydot