Skip to content Skip to sidebar Skip to footer

Align 2 Divs Side By Side

I've never had a problem with aligning divs side by side but for some reason no matter what I do it just doesn't work. I tried a few answers from stackoverflow but they didn't work

Solution 1:

#content {
  background:#eee;
  width: 300px;
  height:auto;
  float: left;
}     

#sidebar {
  background:#c00;
  width: 200px;
  height:auto;
  float:left;
}
<divid="content">Content</div><divid="sidebar">Sidebar</div>

Solution 2:

To answer in a proper way, I need to see more than just two CSS id's, like the HTML page and the CSS file, but I did this:

JSFiddle

And maybe could help you.

Solution 3:

Use float : left, here is a simple example illustrating the usage of floats.

DEMO

Taking your case into account, this css oughta do the trick

#content {
    float : left;
    width: 580px;
    height:auto;
}     
#sidebar {
    float : left;
    width: 270px;
    height:auto;
    float:right;

}

Provided you have a container with a width greater than the sum of the widths of the #sidebar and the #content elements. If the container width is lesser, one will appear below the other as shown in the demo.

Post a Comment for "Align 2 Divs Side By Side"