views:

149

answers:

5

I have a document that looks like

<div id="content">
   <p> blah </p>
</div>

<div id="menu">
   <p> blah2 </p>
</div>

<div id="footer">
   <p> Copyright </p>
</div>

The content div is after the menu div, but is it possible to have the layout displayed like so:

-------------------
| Menu  | Content |
|       |         |
|       |         |
-------------------
| Footer          |
-------------------

How do you swap their order? And I'd rather not use absolute positioning.

+1  A: 

try float:right; on each of them.

Tor Valamo
You'll need to add fixed width to the content div too to prevent the left border from shifting with changing content.
Joel Potter
or relative % will also do. menu: 30%, content: 70%, footer: 100%
Tor Valamo
A: 

I would do the float right on menu and content then a clear both on the footer after setting the width to 100%.

Jeff Beck
+2  A: 

Try some css like this:

#menu {
  float:left;
}
#content {
  float:right;
}
#footer {
  clear:both;
}
John Duff
for some reason, this leaves a small unspecified gap between the menu and content in opera. probably a bug, but still.
Tor Valamo
A: 

Can you alter the HTML code, if that is possible I would do:

<div id="wrapper">
   <div id="menu">
     <p>Blah</p>
   </div>
   <div id="content">
     <p>Blah</p>
   </div>
</div>
<div id="footer">
   <p>Blah</p>
</div>

And style it with:

#wrapper { overflow: hidden; }
#menu { float: left; width: 40%; /* Any size u want */ }
#content { float: left; width: 60%; /* Any size u want */ }

I guess you cant and it is therefore you ask, then I would do as the others say:

#menu { float:right; }
#content { float: left; }
#footer { clear: both; }
Martin
+1  A: 

One problem with the float:right/float:left solutions is the gap between the elements you have to take care of, plus the extra container div.

Another way to do it is:

#content, #menu{
  position: relative;
  float: left;
}
#menu    { right: 500px; }
#content { left: 100px; }
#footer  { clear: both; }

Where 500px is the width of the content, and 100px is the width of the menu. That solution requires relative positioning and fixed width divs.

Isley Aardvark
Your situation is basically what relative positioning is for, moving elements relative to where they would normally be located. "Right" moves the element so its rightmost edge is that number of pixels to the left of where its left edge would normally be. "Left" is vice versa, still going from where its left edge would normally be.
Isley Aardvark