How do you make DIV's that are floated left next to each other not wrap when the browser is re-sized such that the viewport becomes smaller?
div { float: left; }
For example when the browser is fully maximized the div
s line up like this:
|div| |div| |div| |div| |div| |div| |div| |div|
But when the browser re-sized smaller this happens:
|div| |div| |div| |div| |div| |div| |div| |div|
How can I make the div
s not wrap when the browser is re-sized smaller?
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.
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).
In CSS, the float property specifies how an element should float. The floated element will be removed from the normal flow of the page, but it will remain part of the flow — meaning, the element will be shifted to the left or right until it touches the edge of its container or another floated element.
Wrap them in another div, which has a width (or min-width) specified.
<div class="parentContainer"> <div class="floater"></div> <div class="floater"></div> <div class="floater"></div> </div> .parentContainer { /* The width of the parent needs to be equal to the total width of the children. Be sure to include margins/padding/borders in the total. */ width: 600px; overflow: auto; }
It also helps to have overflow: auto specified on the containing div, to allow its height to match the child floats.
I'm pretty late to the game, but here's what I've found that works:
Let's say you have a navigation structured as:
<nav> <ul> <li><a href="#">Example Link</a></li> <li><a href="#">Example Link</a></li> <li><a href="#">Example Link</a></li> </ul> </nav>
To get it to display the links inline, without ever wrapping, you can simply use:
nav ul { white-space: nowrap; } nav ul li { display: table-cell; }
No fixed widths or anything required.
Fiddle: http://jsfiddle.net/gdf3prb4/
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