How can I force a DIV to grow wider than the browser window to accommodate it's children horizontally, rather than forcing them on new rows
i.e. consider the following code with fiddle. There are 6 child elements inside of a container element, all with a minimum width of 200px, and all set to float: left. When the window is resized wide enough they are all on one row. When it is narrowed, they start pushing to new rows. Ideally I would like them to remain on a single row and have the browser display a scroll bar.
http://jsfiddle.net/krippy2k/x8sDp/20/
.container {
}
.child-element {
min-width: 200px;
float: left;
height: 100px;
}
.child1 {
background-color: purple;
}
.child2 {
background-color: orange;
}
.child3 {
background-color: black;
}
.child4 {
background-color: green;
}
.child5 {
background-color: blue;
}
.child6 {
background-color: red;
}
<div class="container">
<div class="child-element child1"></div>
<div class="child-element child2"></div>
<div class="child-element child3"></div>
<div class="child-element child4"></div>
<div class="child-element child5"></div>
<div class="child-element child6"></div>
</div>
Either you can provide a width
to the parent element, else you can use float: left;
with display: inline-block;
and white-space: nowrap;
.container {
white-space: nowrap;
}
.child-element {
min-width: 200px;
display: inline-block;
height: 100px;
}
Demo
For the white-space
of 4px
between each element, you can use margin-left: -4px;
Demo 2
Instead of floating the children, set them to inline block and set white-space:nowrap
on the container.
.container {
white-space:nowrap;
}
.child-element {
display:inline-block;
min-width: 200px;
height: 100px;
}
http://jsfiddle.net/x8sDp/24/
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