views:

35

answers:

4

This is what I want my page to look like:

Mockup

I'm not quite there yet. Here's where I'm at: http://labs.pieterdedecker.be/test/test.htm

I'm quite new to using <div>s (as opposed to <table>s) to create the layout of my pages. How do I get the job done?

A: 

Simply add the below code:

 <div style="clear:both; margin-left:20px;">

after the line:

<div id="body">

That is:

<div id="body">
<div style="clear:both;">

More info about the clear property.

Also, have a look at good tutorial:

Div based layout with CSS

Sarfraz
A: 

the problem i'm seeing now is that your blue 'item' boxes don't look right. i think the reason for that is that the div containing the 'item' boxes should be contained inside the main 'body' box. it is in fact the very first thing inside the 'body' div.

to make this easier on yourself, you should create a div inside the 'body' div, with width: 100% and background: blue (or whatever color that is). then, inside that div you can create your list of items.

the obvious way to put the "items" inside the "item bar" would be to float:left all the items inside their own divs. you would then need to set a static height for the "item bar" itself (like height: 2em), because a div containing only floating elements has no height.

Igor
+1  A: 

try including clear:both in the body div.

  <div id="body" style="clear: both">
    <p>This is my body</p>
  </div>

good luck! ;-)

koss
This fixed the body/menu overlap. Thanks.
Pieter
+1  A: 

You can fix the menu by just adding 2 CSS style rules:

.menu { overflow: hidden; }
.menu ul { margin: 0; }

The overflow will leave a taller menu because of the browser default <ul> margin, just clean this up with the second style, which will knock the margin out.

Nick Craver
The menu bar background now stretches across the page container. Thanks! But why does setting the overflow to hidden cause the DIV to be stretched? I've only used overflow in contexts where I had to cut off text if they didn't entirely fit into the element.
Pieter
@Pieter - It's an alternative way instead of a clearing element. It forces the "overflowed" element to accommodate floating children in it's height calculation is all. There's a full read on it here if you want more info: http://www.quirksmode.org/css/clearing.html
Nick Craver