lets say I got 20 same divs with float:left property and some width. I want them to be in one line and if they dont fit in screen just to make page scroll horizontally.
fiddle
Set size and make inline Because they're block elements, when reducing the size of Div one to make room for the other div, you're left with space next to Div one and Div two below Div one. To move the div up to the next line both div's need to have the inline-block display setting as shown below.
You can force the content of the HTML <div> element stay on the same line by using a little CSS. Use the overflow property, as well as the white-space property set to “nowrap”.
To get all elements to appear on one line the easiest way is to: Set white-space property to nowrap on a parent element; Have display: inline-block set on all child elements.
That's basically how floats work. If you want the described behaviour you can do something else instead, for instance white-space: nowrap;
on the container and display: inline-block;
instead of float.
http://jsfiddle.net/NPzsV/3/
.container {
white-space: nowrap;
}
.line {
display: inline-block;
width: 200px;
vertical-align: top;
white-space: normal;
}
One thing to note though: with this approach, newlines/spaces/tabs between the divs will cause a space between them in the rendering.
Use display: inline-block
instead of float: left
on the divs, and add the property white-space: nowrap
to their parent container.
Demo: http://jsbin.com/akiniv/1/edit
Demo with your fiddle ;) http://jsfiddle.net/NPzsV/4/
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