Reputation: 63577
How can I make a set of squares inside of a div line up in a row, and trigger a horizontal scroll when the squares exceed the div width?
This jsfiddle shows gray squares wrapping incorrectly given a narrow width. The gray squares should always be in 1 row, and the container div should have a horizontal scroll.
Things I've tried:
A variety of position: absolute
and overflow: scroll
attributes. No combination seems to get the desired effect of a scrollable container div.
Upvotes: 0
Views: 786
Reputation: 2328
Check this Demo. Change your container class as follows.
.container {
width: 100%;
height: 120px;
background: rgb(100, 100, 100);
white-space: nowrap;
overflow-y:hidden;
overflow-x:scroll;
}
Upvotes: 0
Reputation: 111
Add white-space: nowrap along with that add a width to your container with scroll x visible and y hidden
<div class="container">
<div style="width: auto; white-space: nowrap">
<div class="thumbnail">
</div>
<div class="thumbnail">
</div>
<div class="thumbnail">
</div>
<div class="thumbnail">
</div>
<div class="thumbnail">
</div>
<div class="thumbnail">
</div>
<div class="thumbnail">
</div>
<div class="thumbnail">
</div>
</div>
.container {
width: 500px;
height: 120px;
background: rgb(100, 100, 100);
overflow-x: scroll;
overflow-y: hidden;
}
Check : http://jsfiddle.net/anqKb/19/
Upvotes: 0
Reputation: 1471
You could use another that contains the squares and set a fixed width.
.setWidth {
width: 740px;
}
Upvotes: 0
Reputation: 206
See http://jsfiddle.net/anqKb/17/ for solution. You needed white-space: nowrap;
so that each of your boxes don't wrap and continue down the page.
So I added that and overflow:scroll;
to .container
and it works.
Upvotes: 0
Reputation: 12146
To make inline-blocks always stay in one row, use white-space:nowrap
on container. Optional overflow (i.e. when content width exceeds parent width) is achieved with overflow:auto
.
Upvotes: 2
Reputation: 1173
Update the css to the following
.container {
width: 100%;
height: 100px;
background: rgb(100, 100, 100);
overflow:auto;
}
Hope this helps
Upvotes: 0