Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to layout sidebar and main body without using 'absolute' or 'float'?

Tags:

html

css

xhtml

I can't for the life of me find a way to make this work.

If I have 3 divs (a left sidebar, a main body, and a footer), how can I have the sidebar and main body sit next to each other without setting their positions as "absolute" or floating them? Doing either of these options result in the footer div not being pushed down by one or the other.

How might I accomplish this regardless of what comes before these elements (say another header div or something)?

In case it helps, here's an illustration of the two cases I'm trying to allow for:

alt text

Here's a simplified version of the HTML I currently have set up:

<div id="sidebar"></div>
<div id="content"></div>
<div id="footer"></div>
like image 911
Wilco Avatar asked Nov 08 '08 02:11

Wilco


People also ask

How do you make a float left aside?

you just need to add float: left; to your <aside> section. Save this answer.

What are float based page layouts?

Float-based layouts take advantage of the float property to position elements side by side and create columns on a web page.

How do I put the header on the left side in HTML?

To set the heading alignment in HTML, we use the style attribute inside an HTML element. The attribute is used with the HTML <h1> to <h6> tag, with the CSS property text-align for setting alignment for an element.

How to position content?

One way to position elements on a page is with the float property. The float property is pretty versatile and can be used in a number of different ways. Essentially, the float property allows us to take an element, remove it from the normal flow of a page, and position it to the left or right of its parent element.


2 Answers

You need to specify the footer to clear the float:

#footer{
 clear: both;
}

This forces it under floated elements.

Other options for clear are left and right.

like image 174
Vincent Ramdhanie Avatar answered Sep 20 '22 14:09

Vincent Ramdhanie


Doing either of these options result in the footer div not being pushed down by one or the other?

Try this tool

like image 26
unigogo Avatar answered Sep 21 '22 14:09

unigogo