I need to create a single line containing a variable amount of (floating?) divs: the container dimension is fixed, and it is supposed to add an horizontal scrollbar when needed, never wrapping.
I tried the following, but it doesn't work: it wraps instead.
div#sub { background-image:url("../gfx/CorniceSotto.png"); width:760px; height:190px; } div#sub > div#ranking { position:relative; top:42px; left:7px; width:722px; height:125px; overflow-x:auto; overflow-y:hidden; } div#sub > div#ranking > div.player { float:left; width:67px; height:120px; margin-left:5px; background-color:#f3e1bb; }
I've tried a few things (inline,table-cell,etc.) but they all failed.
Can this be done? If so, how?
Use "overflow: hidden" to avoid floating elements from wrapping a container's text. Unfortunately, any content of the content 's text will wrap underneath it: ![ paja9.
To clear a float, add the clear property to the element that needs to clear the float. This is usually the element after the floated element. The clear property can take the values of left , right , and both . Usually you'll want to use both.
The float property still exists in CSS as it did when Internet Explorer was a young browser, and still works the same.
Left and Right can be used to only clear the float from one direction respectively. None is the default, which is typically unnecessary unless removing a clear value from a cascade.
Use display: inline-block
instead of float
and give the container white-space: nowrap
.
div#sub > div#ranking { position:relative; top:42px; left:7px; width:722px; height:125px; overflow-x:auto; overflow-y:hidden; white-space: nowrap; } div#sub > div#ranking > div.player { display: inline-block; width:67px; height:120px; margin-left:5px; background-color:#f3e1bb; }
Here an example: http://jsfiddle.net/D5hUu/3/
inline won't work, table-cell should work - see this jsFiddle I made in answer to a similar question:
http://jsfiddle.net/DxZbV/1/
won't work in <=ie7 though...
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