I have defined a div with the CSS:
height: 100%;
width: 360px;
float: left.
Now, I have a button that dynamically adds these divs to the body. The problem is that when there are too many to fit the browser window, they wrap the next div is placed below the others like this.
|bar| |bar| |bar|
|bar| |bar|
|<---- Page width ---->|
Now, what I want is for it to keep on going to the right like this:
|bar| |bar| |bar| |bar| |bar|
|<---- Page width ---->|
And of course, there will be a scrollbar. Is this possible without defining this?
body {
width: XXXpx;
}
If you want to prevent the text from wrapping, you can apply white-space: nowrap; Notice in HTML code example at the top of this article, there are actually two line breaks, one before the line of text and one after, which allow the text to be on its own line (in the code).
It is mostly used with textarea and div elements. To disable resizable property of an element use resize to none.
Alternative way to do this is to use the display:inline-block . Where row element has white-space:nowrap. inline-block makes the element inline but preserves the settings such as width, height, top and bottom margins, paddings.
Use "overflow: hidden" to avoid floating elements from wrapping a container's text. We use flexbox for this use case now. The reason behind this is that " overflow: hidden " will give you a new block formatting context. You could use other attributes as well, but overflow: hidden works nicely without interfering much.
Instead of using float: left;
, you can use display: inline-block;
and wrap in a container using white-space: nowrap;
.
http://jsfiddle.net/Jeff_Meadows/JJ5kT/
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