473,484 Members | 1,697 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Filling the space between two absolute items with CSS

I'm new to the positioning aspects of CSS and I'm going crazy trying to
do something that seems like it should be fairly easy. I've Googled
all over and read CSS tutorials and not found an answer.

I want to divide my screen/page into four areas: a header, a footer, a
menu area, and content. The particular layout I'm trying to accomplish
is to have the header, menu area, and footer stacked on the left and
the content as a full-height column on the right. I have no trouble
placing the header, footer, and content but I want the menu area to
expand to fill the full height from header to footer and to scroll when
necessary. I'll try this in ASCI art:
+--------++------------------------------+
| Header || |
+--------+| |
| || |
| Menu || Content |
| || |
| || |
+--------+| |
| Footer || |
+--------++------------------------------+

It seems that if I wanted three elements across, I could use float to
put the first one on the left and the third one on the right and the
middle would fill but for vertical layout, there doesn't seem to be an
equivalent of float. What combination of position and size can I give
the menu area to make it adapt to how bit the header and footer may be?
Or is there some other setting I need?

TIA.

Jan 26 '07 #1
7 4456
On 2007-01-26, Chris Nelson <cn*****@nycap.rr.comwrote:
I'm new to the positioning aspects of CSS and I'm going crazy trying to
do something that seems like it should be fairly easy. I've Googled
all over and read CSS tutorials and not found an answer.

I want to divide my screen/page into four areas: a header, a footer, a
menu area, and content. The particular layout I'm trying to accomplish
is to have the header, menu area, and footer stacked on the left and
the content as a full-height column on the right. I have no trouble
placing the header, footer, and content but I want the menu area to
expand to fill the full height from header to footer and to scroll when
necessary. I'll try this in ASCI art:
+--------++------------------------------+
| Header || |
+--------+| |
| || |
| Menu || Content |
| || |
| || |
+--------+| |
| Footer || |
+--------++------------------------------+

It seems that if I wanted three elements across, I could use float to
put the first one on the left and the third one on the right and the
middle would fill but for vertical layout, there doesn't seem to be an
equivalent of float. What combination of position and size can I give
the menu area to make it adapt to how bit the header and footer may be?
Or is there some other setting I need?
You can use absolute positioning, something like this:

#header, #menu, #footer
{
position: absolute;
width: 15em;
}

#header
{
/* header is 15em high and starts at the top */
top: 0;
height: 15em;
}

#menu
{
/* menu runs from bottom of header to top of footer */
top: 15em;
bottom: 15em;
}

#footer
{
/* footer is 15em high and runs to the bottom */
height: 15em;
bottom: 0;
}
Jan 26 '07 #2
Chris Nelson wrote:
I'm new to the positioning aspects of CSS and I'm going crazy trying to
do something that seems like it should be fairly easy. I've Googled
all over and read CSS tutorials and not found an answer.

I want to divide my screen/page into four areas: a header, a footer, a
menu area, and content. The particular layout I'm trying to accomplish
is to have the header, menu area, and footer stacked on the left and
the content as a full-height column on the right. I have no trouble
placing the header, footer, and content but I want the menu area to
expand to fill the full height from header to footer and to scroll when
necessary. I'll try this in ASCII art:
+--------++------------------------------+
| Header || |
+--------+| |
| || |
| Menu || Content |
| || |
| || |
+--------+| |
| Footer || |
+--------++------------------------------+
I'll assume Ben's column's width of 15em. Then the below should fulfill
your need of "want[ing] the menu area [Content] to expand to fill the
full height from header to footer and to scroll when necessary".

html, body, #content {height:100%;} /* 100% of viewport height declared
for #content */
body {margin:0;} /* remove default margins all around */
#content
{
margin-left:15em; /* indenting "content" the width of
the left column */
padding:0 1em; /* indent "content" further by 1em
both left and right */
overflow: auto; /* scrolls "content" if greater
height than the viewport */
}
It seems that if I wanted three elements across, I could use float to
put the first one on the left and the third one on the right and the
middle would fill ...
For your layout above, Ben's method using absolute is workable or by
floating left a wrapper containing Header,Menu and Footer and then
"Content" with the same declarations as above would flow to the right of
the wrapper.
... but for vertical layout, there doesn't seem to be an
equivalent of float. What combination of position and size can I give
the menu area to make it adapt to how bit the header and footer may be?
Or is there some other setting I need?
For the left column section, it may be advisable to use fixed height
values for Header and Footer - a percentage height value for Menu, since
it is likely to have a relatively larger height, in order to provide
flex to the column - overflow:auto applied to Menu would provide a
vertical scrollbar to Menu as well if the viewport is too small for a
large listing in Menu.

--
Gus
Jan 27 '07 #3
Gus Richter wrote:
>
For the left column section, it may be advisable to use fixed height
values for Header and Footer - a percentage height value for Menu, since
it is likely to have a relatively larger height, in order to provide
flex to the column - overflow:auto applied to Menu would provide a
vertical scrollbar to Menu as well if the viewport is too small for a
large listing in Menu.
Sorry, I regard Header and Footer as fixed values, but in reality it
isn't for me since I have problems mixing a fixed size and percentages.
Therefore, depending on need, the Header may be something like 25%,
Footer 5% and Menu therefore 70% along with overflow:auto applied.

Ben's method of declaring top and bottom values also provides the flex
and with overflow:auto applied, does the same.

I probably shoulds not have brought up the other method?

--
Gus
Jan 27 '07 #4
On Jan 26, 5:12 pm, Ben C <spams...@spam.eggswrote:
On 2007-01-26, Chris Nelson <cnel...@nycap.rr.comwrote:
... I want the menu area to
expand to fill the full height from header to footer and to scroll when
necessary. ...

You can use absolute positioning, something like this:

#header, #menu, #footer
{
position: absolute;
width: 15em;
}
#header
{
/* header is 15em high and starts at the top */
top: 0;
height: 15em;
}
#menu
{
/* menu runs from bottom of header to top of footer */
top: 15em;
bottom: 15em;
}#footer
{
/* footer is 15em high and runs to the bottom */
height: 15em;
bottom: 0;
}
Thanks but I realize now I wasn't clear about wanting the header and
footer to size to accommodate whatever is put in them (as the page is
loaded) and the menu to size and scroll to show whatever is put in it
(as the window is resized). What you gave me is three fixed-size
areas, right?

Jan 29 '07 #5
On 2007-01-29, Chris Nelson <cn*****@nycap.rr.comwrote:
On Jan 26, 5:12 pm, Ben C <spams...@spam.eggswrote:
>On 2007-01-26, Chris Nelson <cnel...@nycap.rr.comwrote:
... I want the menu area to
expand to fill the full height from header to footer and to scroll when
necessary. ...

You can use absolute positioning, something like this:

#header, #menu, #footer
{
position: absolute;
width: 15em;
}
#header
{
/* header is 15em high and starts at the top */
top: 0;
height: 15em;
}
#menu
{
/* menu runs from bottom of header to top of footer */
top: 15em;
bottom: 15em;
}#footer
{
/* footer is 15em high and runs to the bottom */
height: 15em;
bottom: 0;
}

Thanks but I realize now I wasn't clear about wanting the header and
footer to size to accommodate whatever is put in them (as the page is
loaded) and the menu to size and scroll to show whatever is put in it
(as the window is resized). What you gave me is three fixed-size
areas, right?
The header and footer were fixed height, the menu was variable height.

You can make the footer bottom:0 and height:auto, and you can make the
menu start below an auto height header just by making header and menu
normal-flow blocks (i.e. position:static). But I can't think of a way to
make the menu run from the bottom of an auto-height header to the top of
an auto-height footer fixed to the bottom of the viewport. Sounds like
you'd need a table for that, but setting the table height to 100% of the
viewport doesn't seem to be reliable.
Jan 29 '07 #6
On Jan 29, 12:57 pm, Ben C <spams...@spam.eggswrote:
On 2007-01-29, Chris Nelson <cnel...@nycap.rr.comwrote:
On Jan 26, 5:12 pm, Ben C <spams...@spam.eggswrote:
On 2007-01-26, Chris Nelson <cnel...@nycap.rr.comwrote:
...
Thanks but I realize now I wasn't clear about wanting the header and
footer to size to accommodate whatever is put in them (as the page is
loaded) and the menu to size and scroll to show whatever is put in it
(as the window is resized). What you gave me is three fixed-size
areas, right?The header and footer were fixed height, the menu was variable height.

You can make the footer bottom:0 and height:auto, and you can make the
menu start below an auto height header just by making header and menu
normal-flow blocks (i.e. position:static). But I can't think of a way to
make the menu run from the bottom of an auto-height header to the top of
an auto-height footer fixed to the bottom of the viewport. Sounds like
you'd need a table for that, but setting the table height to 100% of the
viewport doesn't seem to be reliable.
:-(

I played with something like this in an onload() block for the page:

var h = document.getElementById('header');
var m = document.getElementById('menubar');
var f = document.getElementById('footer');
m.style.position='fixed';
m.style.top = computedStyle(h, 'height');
m.style.bottom = computedStyle(f, 'height');

which worked as long as there was no padding in the header but when I
adeed padding the menubar overlays the bottom of the header by the
amount of the padding. I tried adding h.style.paddingTop but it seems
to be blank.

(computedStyle() is from http://javascript.stchur.com/index.php/a/
2006/06/21/p33, maybe there's a better way. The DOM inspector in
FireFox has the right height for the header but the computedStyle
doesn't.)

Jan 29 '07 #7
On 2007-01-29, Chris Nelson <cn*****@nycap.rr.comwrote:
On Jan 29, 12:57 pm, Ben C <spams...@spam.eggswrote:
[snip]
>You can make the footer bottom:0 and height:auto, and you can make the
menu start below an auto height header just by making header and menu
normal-flow blocks (i.e. position:static). But I can't think of a way to
make the menu run from the bottom of an auto-height header to the top of
an auto-height footer fixed to the bottom of the viewport. Sounds like
you'd need a table for that, but setting the table height to 100% of the
viewport doesn't seem to be reliable.

:-(

I played with something like this in an onload() block for the page:

var h = document.getElementById('header');
var m = document.getElementById('menubar');
var f = document.getElementById('footer');
m.style.position='fixed';
m.style.top = computedStyle(h, 'height');
m.style.bottom = computedStyle(f, 'height');

which worked as long as there was no padding in the header but when I
adeed padding the menubar overlays the bottom of the header by the
amount of the padding. I tried adding h.style.paddingTop but it seems
to be blank.

(computedStyle() is from http://javascript.stchur.com/index.php/a/
2006/06/21/p33, maybe there's a better way. The DOM inspector in
FireFox has the right height for the header but the computedStyle
doesn't.)
element.getComputedStyle is the standard function. Note that you get
strings out of it which have to be "parsed".

The whole thing is horrible though-- using tables for layout is nothing
like as bad as using JS.

This works in FF:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<html>
<head>
<title>Test Page</title>
<script type="text/javascript">
function convertHeight(h)
{
return new Number(h.substring(0, h.length - 2));
}

function setMenuHeight()
{
var header = document.getElementById("header");
var footer = document.getElementById("footer");
var menu = document.getElementById("menu");

var style = getComputedStyle(header, null);
var height = convertHeight(style.height);
menu.style.top = height + "px";

style = getComputedStyle(footer, null);
height = convertHeight(style.height);
menu.style.bottom = height + "px";
}

window.onload = setMenuHeight;
</script>
<style type="text/css">
div
{
position: fixed;
width: 10em;
}
#header
{
top: 0;
background-color: lavender;
}
#footer
{
bottom: 0;
background-color: pink;
}
#menu
{
overflow: scroll;
}
</style>
</head>
<body>
<div id="header">
header
<br>
header
</div>
<div id="menu">
menu
<br>
menu
</div>
<div id="footer">
footer
<br>
footer
</div>
</body>
</html>
Jan 29 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1611
by: Jeremy | last post by:
Hi all, I'm playing with XML formatting objects, and have a question on how to insert an expanding vertical space (like <fo:leader>, but vertical) into a document. In LaTeX, this would be...
5
12333
by: Applebrown | last post by:
Hello, basically, I'm just learning intermediate CSS and trying to convert my old table webpage completely to CSS. Hoorah, right? Well, it's not quite going as planned. It's an extremely simple...
0
4454
by: Zac Maclean | last post by:
I have a working version of this in VB, tryign to translate everything over to C#. In the C# version this is filling the listview, the first couple columns are ok, but the last few are going...
6
9026
by: Brian Henry | last post by:
I was wondering how you guys would handle filling a list view with something like 10,000 items which each have 10 sub items on them... there has to be major speed issues with that right? Yet,...
0
1222
by: reidarT | last post by:
I have found a good combobox with multiple fields The example shows filling the combobox from a listview, but I want to fill it with zip-code and cities from a database. The example is as follows:...
1
1262
by: Paolo Pantaleo | last post by:
I have this code from Tkinter import * root=Tk() Button(root).pack(fill=BOTH) root.mainloop() I would expect the button filling all the client draw area of the Frame, but when I resize...
1
1178
by: John | last post by:
Is there an automatic way of filling forms that have been generated using javascript? I tried to use python+mechanize but am having trouble with javascript forms. This is the way the form is...
2
1591
by: rowe_newsgroups | last post by:
Hello all, I have something I believe is something simple, but I can't seem to figure out what to do. I did some searching, but I either can't get my search right. Anyways, on a new webpage I'm...
1
2259
by: ismailc | last post by:
Hi, I've changed an existing xslt file, i found this css file but now the css object is not aligned with the other objects - i checked the other objects they are calling templates. I have...
0
6953
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7105
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7144
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7214
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4845
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3046
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1359
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
592
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
235
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.