Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force a div to grow wider than the browser window

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>
like image 788
Gerald Avatar asked Aug 20 '13 15:08

Gerald


2 Answers

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

like image 120
Mr. Alien Avatar answered Nov 10 '22 03:11

Mr. Alien


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/

like image 27
Andrew Clody Avatar answered Nov 10 '22 03:11

Andrew Clody