6

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 either. I've run out of ideas.

What I have are 2 divs. 1 div is "content" - it has all main info displayed in a table. Second div is "sidebar" - it has just some extra rubbish like images, twitter feed etc.

This is my CSS

#content {
width: 580px;
height:auto;
}     

#sidebar {
width: 270px;
height:auto;
float:right;

}

I've tried to play with positioning, margins, containing those 2 divs in another - wrapper - one but it either doesn't work or creates another problem. Funny enough I am re-writing my old website and even if I copy the old attributes it still doesn't work. Anyone has any idea?

EVERYONE IS ALLOWED TO LAUGHT! LOL

SOLUTION: Delete div #clear which I totally forgot about! What a muppet. :-P Now I feel stupid. :-P

mskfisher
  • 3,291
  • 4
  • 35
  • 48
Vetaxili
  • 609
  • 5
  • 12
  • 22
  • 2
    You probably have to add at least some of the concrete html you're using. Without it's really just guessing. – Yoshi Mar 13 '12 at 11:42
  • possible duplicate of [How to float 3 divs side by side using CSS](http://stackoverflow.com/questions/2156712/how-to-float-3-divs-side-by-side-using-css) – sandeep Mar 13 '12 at 11:44
  • 1
    It's a common thing search that keyword in google & stack you get lost of answers – sandeep Mar 13 '12 at 11:50

3 Answers3

17

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

#sidebar {
  background:#c00;
  width: 200px;
  height:auto;
  float:left;
}
<div id="content">Content</div>
<div id="sidebar">Sidebar</div>
Zoltan Toth
  • 46,981
  • 12
  • 120
  • 134
1

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.

Ashwin Krishnamurthy
  • 3,750
  • 3
  • 27
  • 49
1

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.

Zuazua
  • 87
  • 1
  • 9