Forum Moderators: not2easy

Message Too Old, No Replies

Question about document flow

How to get something to appear under absolutely positioned divs

         

paulpsd

5:14 am on Jan 6, 2005 (gmt 0)

10+ Year Member



I've got a 2 column layout. It goes like this:

.leftnav {
position: absolute;
left: 0px;
top: 0px;
}

.content {
position: absolute;
left: 150px;
top: 0px;
}

In the html:

<div class="leftnav">A bunch of navigation</div>
<div class="content">A bunch of content</div>

Now, underneath both of these columns, spanning the width of both, I want a footer div. The leftnav and the content will not be the same length down the page. I don't know which of these 2 columns will be longer on any given page. However, underneath the longest column, I want to put my footer div.

I could do this with a table easily enough. But how fun would that be?

le_gber

11:11 am on Jan 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi paulpsd,

Try googling for 'exploring footers css'. the first site gives plenty of examples
hope this helps

Leo

paulpsd

6:39 pm on Jan 6, 2005 (gmt 0)

10+ Year Member



Thanks for that. I read through the whole article regarding footers, and came away with the idea that what I want to do makes rocket science and brain surgery look very, very easy.

It looks like I've got to use tables.

le_gber

6:55 pm on Jan 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



no pb,

just a thought why not put a wrapper around the leftnav and content divs and put the footer after this wrapper

something like:

<div id="wrapper">
<div id="leftnav">A bunch of navigation</div>
<div id="content">A bunch of content</div>
</div><!-- end wrapper -->
<div id="footer">your footer</div>

Simply give the wrapper div a fixed height and your footer will always be at the same place, no matter what. Or if you want the footer to be close to the tallest div, personalise the wrapper height by creating a wrapper style for each page (that only works if you don't have too many pages).

Leo

paulpsd

7:04 pm on Jan 6, 2005 (gmt 0)

10+ Year Member



That was my first idea, but it didn't work at all. The footer div appears about 1em down from the top of the left and right divs, completely disregarding how much content they have in them. This is because of the absolute positioning of the wrapper, left and right divs, which remove them from the document flow.

stever

7:12 pm on Jan 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Why not float the two content divs and clear the footer div? There's no need for the divs to be absolutely positioned if those are the correct co-ordinates.

le_gber

7:17 pm on Jan 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think it might work if you remove the absolute pos of the wrapper (if it's aligned top-left within the window it's not mandatory to put the position info). if you wanted to have some space above and on the left of the wrapper (but not centered in the middle of the page) you could use the padding properties on the body tag.

I'll sticky you something I've done today which might help

Leo

paulpsd

7:19 pm on Jan 6, 2005 (gmt 0)

10+ Year Member



I tried using float too. Trouble with float is, the browser support is very spotty. Your suggestion worked in principle, but there were quirky problems. The right div doesn't start right at the top, but is pushed about 1em down from the top. Also, the contents of the left div isn't at the top either, but is also pushed down about 1em.

I looked up "float" in the Eric Meyer CSS book, which reports that its support among browsers is extremely spotty.

Here's the code I used:

<style type="text/css">
.wrapper {
position: absolute;
background-color: red;
left: 150px;
top: 10px;
width: 400px;
vertical-align: top;
}
.left {
float: left;
background-color: yellow;
width: 100px;
vertical-align: top;
}
.right {
background-color: green;
margin-left: 100px;
width: 300px;
vertical-align: top;
}
.bottom {
background-color: blue;
clear: both;
width: 400px;
vertical-align: top;
}
</style>
</head>

<body>
<div class="wrapper">
<div class="left"><p>Left</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
</div>
<div class="right"><p>Right</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
</div>
<div class="bottom">Bottom</div>
</div>

</body>
</html>

createErrorMsg

9:11 pm on Jan 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Trouble with float is, the browser support is very spotty.

I've heard this before but don't see it, myself. The worst float support problem is in IE5/Mac, which admittedly has some issues, but a simple float layout works in the major browsers: Moz, FF, IE5.x and 6, NN (I don't test in Opera or Safari so I'm not sure about those).

Perhaps the "spotty support" refers to the fact that you have to be careful when using floats. Proper floating usually requires the use of other, ancillary properties to make sure that the float behaves in the way you want it to (like margins to demark columns, clears to end the floating, and carefully calculated widths to prevent float wrapping). But if you do all these things correctly, I don't see float as an unreliable layout tool.

The right div doesn't start right at the top, but is pushed about 1em down from the top. Also, the contents of the left div isn't at the top either, but is also pushed down about 1em.

The space you mention is the top margin on the first <p>aragraph in each element. Add this... style="margin-top:0;" to the top paragraphs in .left and .right and the gap you mention goes away.

So this isn't a problem with the float property at all. It's a question of what all the elements on the page are doing, how and why, and in particular how those elements will behave in relation to a float. This makes floats tricky to use, but not unreliable.

cEM

[edited by: createErrorMsg at 9:22 pm (utc) on Jan. 6, 2005]

stever

9:16 pm on Jan 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How about:

.right {
background-color: green;
float: left;
width: 300px;
vertical-align: top;
}

paulpsd

9:32 pm on Jan 6, 2005 (gmt 0)

10+ Year Member



Didn't work. I'm testing this with Safari and IE for Mac, two fairly problematic browsers which the site needs to work on. Basically, float is out except in really simple situations.