I'm working on a album viewer. At the top I want a horizontal container of all the image thumbnails. Right now all the thumbnails are wrapped in a div with float:left
. I'm trying to figure out how to keep these thumbnails from wrapping to the next line when there are too many, but rather stay all in one horizontal row and use the scrollbar.
Here's my code: (I don't want to use tables)
<style type="text/css"> div { overflow:hidden; } #frame { width:600px; padding:8px; border:1px solid black; } #thumbnails_container { height:75px; border:1px solid black; padding:4px; overflow-x:scroll; } .thumbnail { border:1px solid black; margin-right:4px; width:100px; height:75px; float:left; } .thumbnail img { width:100px; height:75px; } #current_image_container img { width:600px; } </style> <div id="frame"> <div id="thumbnails_container"> <div class="thumbnail"><img src="http://www.blueridgexotics.com/images/glry-pixie-bob-kittens.jpg" alt="foo" /></div> <div class="thumbnail"><img src="http://www.blueridgexotics.com/images/PB-KitJan08-1.jpg" alt="foo" /></div> <div class="thumbnail"><img src="http://www.blueridgexotics.com/images/PB-KitJan08-3.jpg" alt="foo" /></div> <div class="thumbnail"><img src="http://www.blueridgexotics.com/images/PB-Jan08.jpg" alt="foo" /></div> <div class="thumbnail"><img src="http://www.blueridgexotics.com/images/gallery3.jpg" alt="foo" /></div> <div class="thumbnail"><img src="http://www.blueridgexotics.com/images/gallery4.jpg" alt="foo" /></div> <div class="thumbnail"><img src="http://www.blueridgexotics.com/Gallery-Pics/kitten3.jpg" alt="foo" /></div> <div class="thumbnail"><img src="http://www.blueridgexotics.com/Gallery-Pics/kitten1.jpg" alt="foo" /></div> </div> <div id="current_image_container"> <img src="http://www.whitetailrun.com/Pixiebobs/PBkittenpics/shani-kits/Cats0031a.jpg" alt="foo" /> </div> </div>
To enable horizontal scrolling, we can use the CSS property overflow-x. If we assign the value scroll to the overflow-x property of the container element, the browser will hide horizontally overflowing content and make it accessible via horizontal scrolling.
The clear CSS property sets whether an element must be moved below (cleared) floating elements that precede it. The clear property applies to floating and non-floating elements.
Note: Absolutely positioned elements ignore the float property! Note: Elements next to a floating element will flow around it. To avoid this, use the clear property or the clearfix hack (see example at the bottom of this page).
What are two valid techniques used to clear floats? Use the "clearfix hack" on the floated element and add a float to the parent element. Use the overflow property on the floated element or the "clearfix hack" on either the floated or parent element.
How about using display: inline-block
this way you can use borders on the block elements and get the horizontal scroll bar.
#thumbnails_container { height:75px; border:1px solid black; padding:4px; overflow-x:scroll; white-space: nowrap } .thumbnail { border:1px solid black; margin-right:4px; width:100px; height:75px; display: inline-block; }
Did you try
white-space: nowrap;
in your #thumbnails_container?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With