Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    May 2008
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Help positioning a div relative to it's parent div

    First of all if you have this code:

    <div id="wrap">
    <div id="content">content</div>
    <div id="footer">footer</div>
    </div>

    Are content and footer considered child divs of the wrap div? And is wrap considered the parent div of content and wrap?

    Now here's my actual css and html
    Code:
    #login {
        height: 70px;
        min-width: 100%;
    }
    #yelblk_stripe {
        height: 5px;
        min-width: 100%;
        background: url(../images/stripe.png) repeat-x;
    }
    
    <div id="login">
        <div id="yelblk_stripe"></div>
        <div id="yelblk_stripe" style="position: absolute; bottom: 0px; left:0px; clear: both;"></div>
    </div>
    How can I get the bottom "yelblk_stripe" div to be along the bottom of the "login" div NOT the page. I also failed to mention the "login" div is located about 1/4 of the way down the page.

  • #2
    Regular Coder
    Join Date
    Feb 2007
    Location
    Canada
    Posts
    924
    Thanks
    10
    Thanked 56 Times in 55 Posts
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <title>
                page title
            </title>
            <style type="text/css">
    /*<![CDATA[*/
            body { margin:0; padding: 0; height: 100%; background-color: green; }
            #wrap{ }
            #login { border: 1px solid black; }
            #yelblk_stripe { height: 15px;  bottom: 0px; clear: both;
                background: url(../images/stripe.png) repeat-x; border: 1px dotted blue; background-color:white;}
            /*]]>*/
            </style>
        </head>
        <body>
            <div>
                <div id="wrap">
    
                    <p>
                        some content here above the div
                    </p>
                    <p>
                        some content here above the div
                    </p>
                    <p>
                        some content here above the div
                    </p>
                    <p>
    
                        some content here above the div
                    </p>
                    <p>
                        some content here above the div
                    </p>
                    <div id="login">
                        <p>
                            login content here
                        </p>
                        <p>
    
                            login content here
                        </p>
                        <div id="yelblk_stripe"></div>
                    </div>
                </div>
            </div>
        </body>
    </html>

  • #3
    Regular Coder
    Join Date
    Aug 2002
    Location
    San Francisco
    Posts
    455
    Thanks
    19
    Thanked 15 Times in 15 Posts
    They are children of the "wrap" div. However, if you want to position something relative to a containing div (as opposed to the browser window), you need to set the position attribute of the containing div to relative.

    #wrap { position: relative; }

    Now anything inside is positioned relative to #wrap.
    Outside of a dog, a book is man's best friend. Inside of a dog it's too dark to read. Groucho Marx

  • #4
    New Coder
    Join Date
    May 2008
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I'm now using this code, but the status div is displayed correctly to the right edge of the viewport, but it's displayed below and not inline to the menu and content divs. WHY??

    Code:
    #wrap {
        width: 100%;
    }
    #header {
        height: 80px;
        width: 100%;
        background-color: gray;
    }
    #menu {
        float: left;
        width: 100px;
        padding: 1em;
        background-color: green;
    }
    #content {
        margin-left: 130px;
        border-left: 1px solid gray;
        margin-right: 330px;
        border-right: 1px solid gray;
        padding: 1em;
        background-color: blue;
    }
    #status {
        float: right;
        margin-right: 0;
        width: 300px;
        padding: 1em;
        background-color: red;
    }
    
    <div id="wrap">
      <div id="header"></div>
      <div id="menu">menu</div>  
      <div id="content">content</div>
      <div id="status">status</div>
    </div>
    Attached Thumbnails Attached Thumbnails Help positioning a div relative to it's parent div-screen.png  

  • #5
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,748
    Thanks
    22
    Thanked 1,838 Times in 1,822 Posts
    Hello Darkmatter5,
    Floats come first. Like this:
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <style type="text/css">
    html, body {
    	font: 12px "Comic Sans MS";
    	background: #FC6;
    	text-align: center;
    }
    * {
    	margin: 0;
    	padding: 0;
    	border: none;
    }
    #wrap {
    	margin: 30px auto;
    	background: #999;
    	overflow: auto;
    }
    #header {
    	height: 80px;
    	width: 100%;
    	background: #CCC;
    }
    #menu {
        float: left;
        width: 100px;
        padding: 1em;
        background: #090;
    }
    #content {
        margin-left: 130px;
        border-left: 1px solid gray;
        margin-right: 330px;
        border-right: 1px solid gray;
        padding: 1em;
        background: #00f;
    }
    #status {
        float: right;
        margin-right: 0;
        width: 300px;
        padding: 1em;
        background: #f00;
    }
    </style>
    </head>
    <body>
        <div id="wrap">
            <div id="header"></div>
            <div id="menu">menu</div>  
            <div id="status">status</div>
            <div id="content">content</div>
        <!--end wrap--></div>
    </body>
    </html>
    Moved the bit in red.
    Last edited by Excavator; 02-27-2009 at 05:02 PM.
    Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
    Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad

  • Users who have thanked Excavator for this post:

    Darkmatter5 (02-27-2009)

  • #6
    New Coder
    Join Date
    May 2008
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks worked great!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •