Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS: series of floated elements without wrapping but rather scrolling horizontally

Tags:

css

layout

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> 
like image 796
tybro0103 Avatar asked Mar 03 '10 17:03

tybro0103


People also ask

How do I scroll horizontally in CSS?

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.

Can clear property apply to floating and non floating elements in CSS?

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.

Which CSS property is used to prevent elements from floating?

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?

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.


2 Answers

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; } 
like image 152
gdelfino Avatar answered Sep 22 '22 23:09

gdelfino


Did you try

white-space: nowrap; 

in your #thumbnails_container?

like image 39
Robusto Avatar answered Sep 21 '22 23:09

Robusto