Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Put divs below float:left divs

Tags:

html

css

I'm trying to have a site that has the basic structure:

<1 div>  
<3 divs next to each other>  
<1 div> 

The 3 divs are float:left in order to make be on the same level. However, they 5th div (at the bottom) sort of moves up to the top of the 3 divs in IE, and shown like that in Chrome, although the content is below the 3 divs.
I think I've just done some lazy coding here, but don't really know any better.
I've currently got:

<div id="results">
<!-- Ajax Content Here -->
</div>
<div id="leftpanel">
</div>
<div id="photo">
</div>
<div id="top3">
</div>
<div id="voting">
</div>

The results is the top one, leftpanel, photo and top3 are the middle 3, whilst voting is below the 3.
Basic CSS is :

#leftpanel {
float:left;
width:20%;
height: 600px;
}

#top3 {
float: left;
width:20%
}

#photo {
width: 60%;
float:left;
text-align: center;
}

#voting {
width: 500px;
height: 250px;
text-align: center;
margin-left: auto;
margin-right: auto;
}

#results{
width: 300px;
height: 20px;
margin-left: auto;
margin-right:auto;
margin-bottom: 5px;
text-align: center;
}

I'm sure it's something silly I'm doing, so any input is much appreciated, I could use to learn how to do this properly :) I previously had a containing div on the 3 middle divs, but this didn't work since the ones inside change size. Maybe I need to do this, but in a different way?

like image 723
Joseph Duffy Avatar asked Oct 13 '11 20:10

Joseph Duffy


People also ask

How do I make my div float to the bottom?

Set position value to absolute and bottom value to zero to placed a div at the bottom of container.

How do I get two divs under each other?

With CSS properties, you can easily put two <div> next to each other in HTML. Use the CSS property float to achieve this. With that, add height:100px and set margin.

How float left and right in div?

Use CSS property to set the height and width of div and use display property to place div in side-by-side format. float:left; This property is used for those elements(div) that will float on left side. float:right; This property is used for those elements(div) that will float on right side.

Why is my div on the left?

It means that the div will spread on the entire width of the page. Try deleting this width attribute, and beside that delete all float attributes.


3 Answers

add clear: both to the bottom div, so it won't be influenced by the floating other divs, but will move down below them.

like image 155
GolezTrol Avatar answered Nov 03 '22 11:11

GolezTrol


Rather than working with floats, you might consider simply setting the display attribute of the middle divs to "inline-block". Remember that be default, div elements have a block display, which means that they take up the entire width of its parent element, even if its width is less than the parent width. inline blocks on the other hand fit together like puzzle pieces and flow horizontally rather than vertically. I think this would make your code much cleaner than dealing with floats. Here's a demo:

http://jsfiddle.net/scMFC/

like image 36
Eric Rowell Avatar answered Nov 03 '22 11:11

Eric Rowell


You need to clear the floats. If #voting is your fifth div add this in your css.

#voting{clear:both}

should do the trick

like image 13
locrizak Avatar answered Nov 03 '22 09:11

locrizak