Meaningless Drivel is fun!
The moose likes HTML, CSS and JavaScript and the fly likes CSS & DIV relative alignment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply locked New topic

CSS & DIV relative alignment

Kevin P Smith
Ranch Hand

Joined: Feb 18, 2005
Posts: 362

Im kinda new to using DIVs for structuring my website (previously used the ancient and static prehistoric method of tables!).
It all seems pretty straight forwards but I have come across an issue with 'relative' positioning.

How do you make DIV alignment 'relative' to the other divs around it?
By that I mean if I have a DIV(a) that is top/left 0 and has a height of say 50px, and I want another
DIV(b) below it, which is 30px high.
I can set the top of DIV(b) as 50px but if the height of DIV(a) changes then DIV(b) will be wrong. How do I
say that I always want DIV(b)s top to be relative to the height of DIV(a)?

Here is a simple example of a DIV layout that gives me a 'header,'topnav','left nav','body' and a 'footer'.
If I changes the height of 'header' how could I move the top of 'leftnav' and 'topnav' without having to go
thoruhg the CSS and physically make the changes. Also I always want 'body' to be relative to ALL the other DIVs so that it is always inside the topnav, leftnav & foot space.

As my website gets more complex this would become more and more of an issue.

Cheers in advance


OK, getting a bit closer (I think)

But the problem I have here is that the leftnav is longer than the browser window size and the content div is below the rest of the page layout.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63873

Please do not post the same question more than once. As you have re-posted this, I'll close this one.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: CSS & DIV relative alignment
It's not a secret anymore!