I have a page with a body that's 960px wide and I have a row of images that I want to overflow out of the right side of the page, and allow for the display of the overflowed images and horizontally scrolling. I don't want the page as a whole to horizontally scroll, just that element.
It's relatively easy to get the horizontal scrolling to work, but I can't get the overflow images to show without also increasing the width of the entire page (and, hence, making the page horizontally scroll).
My CSS:
container{
width:960px;
margin: 0 auto;
}
.pic-container {
white-space:nowrap;
overflow:scroll;
}
My (simplified) HTML:
<body>
<container>
<div class="pic-container">
<div class="pic-row">
<img src="1.jpg">
<img src="2.jpg">
<img src="3.jpg">
<img src="4.jpg">
<img src="5.jpg">
<img src="6.jpg">
</div>
</div>
</container>
</body>
Here's a little diagram of what I'm looking for:
I couldn't figure out a way to do this with just html + css so I leaned on JQuery. This actually works perfectly, and it degrades nicely too — if there's no javascript, the images are still scrollable, they just don't bleed into the right margin (the '.pic-container' div by default has no width until the js adds it in).
This might do what you're looking for (see on JSFiddle here):
CSS:
What we do is hide the overflow of the
body
, which prevents the horizontal scrollbars, even if the page isn't wide enough to show everything. Then you make it show the scrollbars on the containerdiv
, with a set width (presumably, the width of your document) and make the content within thatdiv
as wide as you want.Another implementation, which just sets the width of the
section
instead of thebody
, can be viewed here.