Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop divs from wrapping?

Tags:

html

css

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;
}
like image 201
Student of Hogwarts Avatar asked Feb 07 '13 21:02

Student of Hogwarts


People also ask

How do I force div to not wrap?

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).

How do I stop DIVS from resizing?

It is mostly used with textarea and div elements. To disable resizable property of an element use resize to none.

How do I stop DIVS from floating?

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.

How do you keep a floating element from wrapping?

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.


1 Answers

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/

like image 185
Jeff-Meadows Avatar answered Sep 27 '22 17:09

Jeff-Meadows