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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Apr 2011
    Posts
    5
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Absolute positioning of a Div inside a Div

    I have my Div's with a margin: 0px auto; to compensate for wider monitors. Problem is, I want to position another div inside one of these divs but when I do absolute positioning, it keeps doing it from the upper left of the browser. How do I get it to position from the the upper left corner of the Div it is inside?

    Here is my code inside my css stylesheet:

    Code:
    #header {
      width: 800px;
      height: 70px;
      margin:0px auto;
      text-align:left;
      background-color:#fff;
    }
    
    
    #insideheader {
       position: absolute;
       top:   20px;
       left:  720px;
       width: 175px;
       height: 30px;
       text-align:left;
       background-color:#fff;
    }
    And here is my code from the html:

    Code:
    <div id="header">
      <img src="Graphics/Smaller title.png">
      <div id="insideheader">
        <table align = "center">
          <tr>
            <td><font size="2" font color="gray">Terms Of Use</font></td>
            <td></td>
            <td class="leftedge2"></td>
            <td><font size="2" font color="gray">Contact Us</font></td>
          </tr>
       </table>
      </div>
    </div>
    What am I doing wrong? Or what should I be doing differently?

    Thanks!!

  • #2
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    set position: relative; on the outer div and position: absolute on the inner div. The top and left styles on the inner div will then be relative to the top left hand corner of the outer div.

  • Users who have thanked bullant for this post:

    eaglei22 (04-29-2011)

  • #3
    New to the CF scene
    Join Date
    Apr 2011
    Posts
    5
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thanks a bunch! Worked like a charm.

  • #4
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    you're welcome


  •  

    Posting Permissions

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