473,549 Members | 2,715 Online
Bytes | Software Development & Data Engineering Community
+ 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 4461
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.getEle mentById('heade r');
var m = document.getEle mentById('menub ar');
var f = document.getEle mentById('foote r');
m.style.positio n='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.padding Top 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.getEle mentById('heade r');
var m = document.getEle mentById('menub ar');
var f = document.getEle mentById('foote r');
m.style.positio n='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.padding Top 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.getComp utedStyle 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.substr ing(0, h.length - 2));
}

function setMenuHeight()
{
var header = document.getEle mentById("heade r");
var footer = document.getEle mentById("foote r");
var menu = document.getEle mentById("menu" );

var style = getComputedStyl e(header, null);
var height = convertHeight(s tyle.height);
menu.style.top = height + "px";

style = getComputedStyl e(footer, null);
height = convertHeight(s tyle.height);
menu.style.bott om = 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
1624
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 roughly equivalent to a \hfil I have a document with a table, which has a variable number of items. I want the footer of this table to always appear...
5
12337
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 layout, and I'm finding myself stuck with small white space in between my images where I planned for the graphics to be stacked up right on top of one...
0
4460
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 screwy. In VB, it is working perfectly. The reason for move is speed. Takes a full 10 - 15 seconds to run this on VB, <5 in C#. I adapted this from
6
9033
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, applications like outlook and such can retrieve and display tens of thousands of emails with virtually no performance hit at all... how would we go about...
0
1229
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: Dim dtLoading As New DataTable("UsStates") dtLoading.Columns.Add("Name", System.Type.GetType("System.String")) ...
1
1271
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 the root window the button becomes wider, but
1
1181
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 created: <script...
2
1596
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 creating (I'm not a designer by any means) I want to have a Div in the center that hoses all the pages content. I want the div to fill the entire...
1
2272
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 added the code in <td align-'left'> but the objects are out by a space to the css object i added: How do i add a space/move the select box up by a...
0
7956
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7469
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7808
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6040
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5368
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5087
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3498
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1935
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 we have to send another system
1
1057
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.