I’m trying to create the following layout for my website:
<table width="80%" align="center">
<tr>
<td width="80%" bgcolor="red">MAIN CONTENT</td>
<td bgcolor="green">SIDEBAR</td>
</tr>
</table>
As you would imagine this will create a table that is 80% of the page width and the content area is 80% of that width, while the sidebar fills the rest.
But this time I want to use DIVs or SPANs or basically a TABLEless design. Now, I know I can use two DIVs and use their “float” properties to achieve this but I was hoping to see if there is something more simple and more logical like this:
<div align="center" style="width:80%">
<span style="width:80%;">
MAIN CONTENT
</span>
<span>
SIDEBAR
</span>
</div>
Unfortunately the above does not work at all and I don’t know why. Can someone please show me the purest HTML implementation for it which does not use “float”?
Every site I see on the internet nowadays has at least one sidebar so I’m hoping your answer to this will help a lot of people besides me. Thanks!
You can do this without using floats by using proper markup and
display: table;,display: table-cell;with CSS.HTML:
CSS:
But beware, IE7 and lower do not support this CSS.
http://jsfiddle.net/57Fvk/
Using almost the same markup (one extra div) you can use floats to create the desired layout also:
HTML
CSS:
http://jsfiddle.net/shzLc/