Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Align 2 Divs side by side [closed]

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

like image 830
Vetaxili Avatar asked Mar 13 '12 11:03

Vetaxili


People also ask

How do I show two divs on the same line?

To display multiple div tags in the same line, we can use the float property in CSS styles. The float property takes left, right,none(default value) and inherit as values. The value left indicates the div tag will be made to float on the left and right to float the div tag to the right.

How do I center two divs inside a div?

Simply put, if you have a div, and the elements inside are set to “display:inline-block” then you can just use “text-align:center” to center them inside.

How do I vertically align two divs?

To align two <div> elements vertically in Bootstrap 3, you can try using the CSS Flexible Box Layout. In the example below, we display the needed row as a flex container box with the CSS display property and then, align the flex-items (columns) vertically with the align-items property.


2 Answers

#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>
like image 96
Zoltan Toth Avatar answered Oct 05 '22 02:10

Zoltan Toth


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.

like image 38
Zuazua Avatar answered Oct 05 '22 00:10

Zuazua