0

I have the following html code:

<html>
    <body>
        <style>
            div{border:solid 1px;}
            .cool{width:400px;height:102px; overflow:auto;}
            .cool div{width:100px;height:100px;}
        </style>
        <div class="cool">
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
        </div>
    </body>
</html>

Try it here

It is giving a vertical scrollbar but i want horizontal .How can i get it?

4

3 回答 3

3

http://jsfiddle.net/H3UWg/1/

Added display: inline-block to .cool div and white-space: nowrap to .cool

于 2012-05-16T12:48:28.793 回答
1

If you want the divs to stay inline rather than block, there are a few ways. Personally, I hate float:left.

Try this:

    .cool{width:400px;height:122px; overflow:auto;white-space:nowrap;}
    .cool div { width:100px;height:100px;display:inline-block;zoom:1;*display:inline; }

Note: The zoom:1;*display:inline; business is an IE7 or less hack

http://jsfiddle.net/HackedByChinese/tPb2v/

于 2012-05-16T12:46:34.797 回答
0

This probably isn't what you are hoping for infact I think the other answer are better! But as an alternative, you could have a containing div inside .cool that has a predefined width.

e.g. http://jsfiddle.net/alexkey/Vs5Wk/

于 2012-05-16T12:53:00.153 回答