Forum Moderators: not2easy

Message Too Old, No Replies

Floated left nav should be 100% height of floated content div.

How can one achieve this?

         

SilverLining

9:51 am on Apr 25, 2007 (gmt 0)

10+ Year Member



(Following on from this post [webmasterworld.com]). I have since fixed the form tags breaking the layout, however the left Nav does not stretch all the way down the page, except in IE. In Firefox, the left nav sometimes does extend down e.g. when I click on the Firebug green tick and then close it, it forces the div to 100%. Also scrolling down the page and up again sometimes forces the 100% left nav height in FF (a bit like the Peekaboo IE bug...)

Both divs are inside a containing div. The left nav floats left and the content div floats left against it. I floated the content div left here, instead of right, because of the problems which were caused by margins and padding in IE.

Some code extracts:

CSS


#nav {width: 168px; background: url(bg.gif) #fc3 repeat-y 0% 0%; margin-right: 25px; height: 100%; display: table;}
#template #contentSurround {height: 100%; display: table-cell;}

HTML


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xml:lang="en">
<head>
<title>Test page</title>
<link rel="stylesheet" media="all" href="blah.css" type="text/css" />
</head>
<body>
<div id="page">
<div id="template">
<div id="contentSurround">
<div id="header"></div>
<div id="nav">
Left Nav should stretch to 100%
</div>
<div id="container">
<div id="content">
Content
</div>
<div id="nav2">
nav2
</div>
</div>
</div><!-- /contentSurround -->
</div><!-- /template -->
</div><!-- /page -->
</body>
</html>

Fotiman

Your #nav is floated left. You're also trying to specify the height as 100%. However, it can only determine the height if it is explicitly set on it's parent. But floating the element takes it out of the flow, it can't calculate 100%.

Fotiman, thanks for that insight! Is the only way to fix this, changing the stucture to a table-layout?

I have another question regarding this layout. I need a footer at the bottom of the page, which stretches across the width of the page, but through the left nav. Easily done at the top of the page (for example background image lines set on the body tag, with margin-top), but how can this be achieved at the bottom of the page?

Apologies if this post is unclear, I'm not great with explaining things. Appreciate any help! Thanks.

SilverLining

10:23 am on Apr 25, 2007 (gmt 0)

10+ Year Member



Update: Sometimes the left nav runs down to the bottom of the page and other times it only loads up to a certain point. It looks like if the page loads before the ads in the page, and allows the left nav to finish loading, then all is ok.

Dabrowski

1:05 pm on Apr 25, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have had a similar issue with a site I'm working on. The way I got around it was by using absolute position and defining all 4 edges (top, left, bottom and right). But then you need some JS to make it work in IE6. I'll give you this if you want, just send me a sticky.

Why do you need it to be 100% height? Is it for a background? You might want to look up 'faux columns'.

SilverLining

4:53 pm on Apr 25, 2007 (gmt 0)

10+ Year Member



Thanks Dabrowski. Yes, it is for a background. Looking into faux columns for now. Thanks for the tip.

SilverLining

3:47 pm on Apr 26, 2007 (gmt 0)

10+ Year Member



Easy fix: I just set the background on
div.template
, because this div will stretch according to the content inside it.

Still need to find a solution for the footer though.

Dabrowski

6:15 pm on Apr 26, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Can't find your footer, do you mean nav2?

Also does your page work in IE? I doubt it will as it doesn't support display table or table-cell properly.

SilverLining

11:35 am on Apr 27, 2007 (gmt 0)

10+ Year Member



Dabrowski - the footer was a general question, which I hadn't specifically added in the code, although nav2 could be replaced by 'footer'. Sorry.

The layout has since changed...

I have created a placeholder for the footer inside the template. And then added the footer after the page div with a negative margin-top. This ensures that the left nav background runs all the way down and the footer is 100% screen-width as opposed to 100% template-width. Makes sense?

To answer your question: Yes, layout works in both FF and IE now. I think I had to add

display: table
and
display: table-cell
for it to work in Firefox.

Dabrowski

12:09 pm on Apr 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Not quite sure what you mean, but ideally you'd want to mirror the header, so using your code above, do this:

<div id="contentSurround">
<div id="header"></div>
<div id="nav">
Left Nav should stretch to 100%
</div>
<div id="container">
<div id="content">
Content
</div>
<div id="nav2">
nav2
</div>
</div>
<div id="footer"></div>
</div><!-- /contentSurround -->

Which is probably what you meant. You should be careful about using table/table-cell, if M$ decide to support it in the future, and in the spirit of IE, don't do it right, your page could break when a future browser is released.

Try to do it without these if you can. If you tell me what and where the areas are on the page I can probably mock up a CSS layout. Besides, I've been brushing up on my CSS and I need the practise!