Forum Moderators: not2easy

Message Too Old, No Replies

columns at different levels.

         

ajnorris

11:23 pm on Oct 28, 2004 (gmt 0)

10+ Year Member



Ok, so I have a two column layout on my website with a header and footer. What I want to do is have the left side column start a little higher than the right hand column. I can get this effect to work the other way around, but I can't get the right hand column to move down! Help, please!

Here is the code for the two columns, with #side as the left and #chunk as the right.

#side
{
float: left;
margin: 0px 0px 0px 5px;
padding: -5px 5px 0px 0px;
width: 143px;
}

#chunk {
text-align: center;
padding: 0px 10px 10px 10px;
margin: 20px 20px 0px 165px;
border-width: 1px;
border-color: #3399FF;
border-style: solid;
background-color: #FFFFCC;
border-collapse: collapse;
}

SuzyUK

7:18 pm on Nov 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ajnorris..

apologies for missing this for so long.. I'm only recently beginning to see the benefits of using floats to contain floats (aside from stretching divs) this is one case where it will work to do what you want.

Simply wrap a 100% wide floated div around the entire layout and you should be able to achieve it fairly well..


<style type="text/css" media="screen">
#wrapper {
float: left;
width: 100%;
background: #eee;
}

#side
{
border: 1px solid #000;
float: left;
margin: 0px 0px 0px 5px;
padding: 5px 5px 0px 0px;
width: 143px;
}

#chunk {
text-align: center;
padding: 0px 10px 10px 10px;
margin: 100px 20px 0px 165px;
border-width: 1px;
border-color: #3399FF;
border-style: solid;
background-color: #FFFFCC;
}
</style>
</head>
<body>
<div id="wrapper">
<div id="side">side text</div>
<div id="chunk">chunky text</div>
</div>

I don't know why yet?

Suzy

createErrorMsg

8:46 pm on Nov 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't know why yet?

Could it be collapsing margins?

From the W3 Specs [w3.org]...

Vertical margins between a floated box and any other box do not collapse (not even between a float and its in-flow children).

By putting #chunk inside of a floated container, it forces the margins not to collapse. Which would also explain why ajnorris was able to make this scheme work in reverse; the left div is floated and therefor does not collapse it's margins.

The question, then, is exactly what margin was collapsing with those of #chunk...

SuzyUK

9:17 pm on Nov 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Could it be collapsing margins?

Yep that's what I was thinking too but never tested it..
~ * {padding: 1px;}

I think you're absolutely right and in my code it's actually collapsing with the default body margin (because I haven't zero'd it} ..

I was thrown by IE getting it "right", but of course it's float model is different and the "chunk" element is not actually 100% wide (like it should be)

So what's happening in compliant browsers is that the 100% wide "chunk" element's margin has collapsed to it's parent element (body in my case) so the float is being affected by the body margin too..

IE on the other hand.. well it's side and chunk elements are not overlapping so they're doing their own thing anyway.

So in this case 1px top padding on the parent element will also fix it..

Thanks cEM.

Suzy

ajnorris

12:50 am on Nov 20, 2004 (gmt 0)

10+ Year Member



Sorry about the late thanks, but thanks for the help nonetheless! You all fixed my problem. Of course, I still have about a million others to take care of, but one is out of the way!