0

Whenever I resize the browser, the 2nd div in .container positions below the first one.

<div class = "container">
     <div class = "one"></div>
     <div class = "two"></div>
</div>

The divs are really blank.

CSS

.container{
    overflow: hidden;
    width: 810px;
    min-width: 810px;
}
.one,.two{
    width: 300px;
    height: 450px;
}
.one{float:left}
Mr. Alien
  • 153,751
  • 34
  • 298
  • 278
user2586153
  • 136
  • 1
  • 10

3 Answers3

3

I just realized that, you are not floating the other element, this is causing it to shift down, you should use float: left; or right as it's a div so it will take up entire horizontal space, and hence it is pushed down.

Demo

.one, .two{
    width: 300px;
    height: 450px;
    float:left; /* Float both elements */
    background: #f00;
}

Alternative

You should use display: inline-block; and white-space: nowrap; to prevent the wrapping of the elements

Demo

This will gave you the same effect, the only thing is 4px white space, you can simply use

.two {
   margin-left: -4px;
}

the above will fix the white space issue for you

Demo 2

Mr. Alien
  • 153,751
  • 34
  • 298
  • 278
0

Add this CSS. Demo.

.two {
    margin-left: 300px;
}

PS: When works with float, you should clearfix.

Community
  • 1
  • 1
long.luc
  • 1,191
  • 1
  • 10
  • 30
0

Give your body a minimum width:

body {
    min-width: 1110px;
}

Then, when the viewport gets smaller than 1110px the scrollbar will appear.

Note: if you add margin, padding or border to the divs, add it to the min-width of the body (or take some extra space).

GreyRoofPigeon
  • 17,833
  • 4
  • 36
  • 59