Grow your CSS skills. Land your dream job.

Need help with complex absolute & relative positioning…

  • # December 8, 2009 at 11:27 am

    Guys, I stumbled upon Chris’s article about relative and absolute positioning and have read a few other resources, but I cannot seem to find the answer to my current problem.

    Currently, I have the following layout:

    <div id="wrapper"> (width of 100%)
    <div id="content_wrap"> **width:980px; **
    <div id="header"> (width:950px; margin:0 auto;) </div>
    <div id="container"> ** position:relative **
    <div id="page_content"> ** position:absolute: width:695px; z-index:99; top:0; left:0;**
    <div class="head"></div>
    <div class="body"></div>
    <div class="foot"></div>
    </div><!– #page_content –>
    <div id="rightcol"></div> ** position:absolute; width:300px; z-index:3; top:25px; left:680px; **
    </div> <!– END #container –>
    </div> <!– END #content_wrap –>
    <div id="footer"></div>
    </div> <!– END #wrapper –>

    Essentially, I want the div "page_container" to appear on top of (hover I guess) the "rightcol" div. I have the "rightcol" div set to appear 25px down from the top of the "container" div and 680px from the left of it as well. I did this to have "page_container" overlap "rightcol" due to some PNG transparent images I am using.

    PROBLEM: The div id"footer" is showing up directly under the "content_wrap" div. Like it is ignoring the "header" and "container" div’s all together, eventhough I have those two set at relative positions.

    QUESTION: Is there a way to "clear" the positioning before the "footer" div? What am I missing here?

    Thanks ya’ll!
    Chris

    # December 8, 2009 at 2:50 pm

    Probably the best way to do it is to use a sticky footer to absolute position your footer to the bottom of the page…

    # December 8, 2009 at 3:12 pm

    Sounds like a job for a stickyfooter.

    But… I did a little testing to see what would happen if you just wanted to mess with only the css you have and this appears to be functioning in ie6/7 and ff…

    Basically you’d set your footer for absolute position as well with a position of bottom:0px; and then stick it in your page content div. Maybe I’m just being sloppy not using the stickyfooter method, but it appears to work :P

    Code:

    Code:
    body {
    margin:0;
    padding:0;
    }

    #wrapper {
    width:100%;
    }

    #content_wrap {
    width:980px;
    background-color:#eee;
    }

    #header {
    width:950px;
    height:100px;
    background-color:#fff;
    margin:0 auto;
    }

    #container {
    position:relative;
    }

    #page-content {
    background-color:#ccc;
    position:absolute;
    width:650px;
    z-index:99;
    top:0;
    left:0;
    }

    #rightcol {
    position:absolute;
    width:300px;
    z-index:3;
    top:25px;
    left:680px;
    background-color:#777;
    height:500px;
    }

    #footer {
    background-color:#000;
    width:980px;
    height:50px;
    position:absolute;
    bottom:0px;
    }

    # December 8, 2009 at 3:59 pm

    xheathen, Thank you for the reply. That would work but the footer div needs to be 100% wide and not inside the container div… sorry I did not mention that in the OP.

    # December 9, 2009 at 9:09 am

    I take it this positioning problem is not fixable with valid CSS? Ok…guess it is time for That CSS guy ad I saw here on the site…lol.

    I will still check this forum to see if a solution has been found, but in the mean time, I have to get this fixed. Thanks for the help guys!

    # December 9, 2009 at 1:29 pm
    "meenainc" wrote:
    I take it this positioning problem is not fixable with valid CSS?

    Sticky Footer is valid CSS, and it’s very easy to make the footer 100% wide… Just make a container Div that is 100% wide.

    Did you read through any of the ways to make a sticky footer? Learning the how will make it easy to do what you want to do with it.

    # December 9, 2009 at 3:38 pm

    Ashton, yes I did read how to make a sticky, but thanks for the sarcastic question. Instead of valid CSS I should have said, "settle for making a design change."

    The sticky footer does not work like you suggest even when moved outside of the "wrapper" div as the "wrapper" div is not expanding in height for some reason. Using Inspect Element in FF when you scroll over the "wrapper" div, it only shows that it is as tall as the "header" div, even though every other div is inside of it.

    My solution was to forgo the positioning and "float above" all together and make a minor design change. I still want to find a solution to this.

    # December 9, 2009 at 3:59 pm
    "meenainc" wrote:
    Ashton, yes I did read how to make a sticky, but thanks for the sarcastic question. Instead of valid CSS I should have said, "settle for making a design change."

    I’m sorry if it read as sarcastic. Your valid css comment made it sound like you hadn’t read it, so I had to ask.

    "meenainc" wrote:
    The sticky footer does not work like you suggest even when moved outside of the "wrapper" div as the "wrapper" div is not expanding in height for some reason.

    I’m not totally sure what you mean, but this, but there is nothing specific to Sticky Footer that demands the footer to be a certain width. If you go to that page and use Firebug to remove the width from the #wrapper and #footer, the footer is 100%.

    This may mean that you will need to update your markup to have another Div inside the wrapper that keeps your text from being 100% (or adding a new wrapper outside your existing content, etc.) Does that make sense?

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".