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 to the CF scene
    Join Date
    Nov 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Centering Page in Browser

    Hi, I'm not really a coder, but I am trying to do something in dreamweaver that I can't figure out how to do. I have spent plenty of time trying to figure it out, and I've posted my code below. Basically, I just want my page to center in any browser, but at this point, it is aligning on the left side in both Firefox and IE8. Could anyone tell me what I'm doing wrong?

    Here is the code:



    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    <style type="text/css">
    body {
    text-align: center;
    }
    #container {
    margin: 0 auto 0 auto;
    width: 1000px;
    height:1000px;
    text-align: left;
    }
    </style>
    </head>
    <style type="text/css">


    #Layer1 {
    position:absolute;
    width:17px;
    height:12px;
    z-index:1;
    left: 492px;
    top: 22px;
    }
    #Layer2 {
    position:absolute;
    width:409px;
    height:263px;
    z-index:2;
    left: 20px;
    top: 21px;
    }
    #Layer3 {
    position:absolute;
    width:16px;
    height:11px;
    z-index:3;
    left: 979px;
    top: 22px;
    }
    </style>
    <body>
    <div id="container">
    <div id="Layer1">
    <p>Center</p>
    </div>
    <div id="Layer2"><img src="imagesunder_construction.jpg" width="451" height="335" /></div>
    <div id="Layer3">Right</div>

    </div>
    </body>
    </html>



    Here is the page that shows up:

    http://heritagelandscaping.ca/12345.html



    Thanks in advance for your help. Mike

  • #2
    Senior Coder
    Join Date
    Aug 2010
    Location
    High Point, NC
    Posts
    3,338
    Thanks
    5
    Thanked 363 Times in 360 Posts
    Your container div is centered....give it a thin solid red border and you will see.

    I think you probably closed the container div too soon. It should be closed right before the closing body tag.

  • #3
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Okay, I see what you're saying... I added a border, and I see the container is centered. However, I don't understand why the layers aren't within the container. I assume it's something to do with the code below, but I can't seem to find the problem. I did close the container div right before the closing body tag. Can you see anything wrong with this?


    <body>
    <div id="container">
    <div id="Layer1">
    <p>Center</p>
    </div>
    <div id="Layer2"><img src="imagesunder_construction.jpg" width="451" height="335" /></div>
    <div id="Layer3">Right</div>

    </div>
    </body>
    </html>

  • #4
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,675
    Thanks
    22
    Thanked 1,827 Times in 1,811 Posts
    Hello Mike521266,
    Your containing div, #container, needs to be position: relative; so your absolute positioned elements stay with their container.

    You also have #Layer2 set at width:409px;height:263px; but the image in it is much bigger at width:451px;height:335px;

    I prefer putting a background color on divs for testing. If you use a border you stand a good chance of inadvertantly wrecking your box model.

    Try some of these changes to your CSS -
    Code:
    body {
    text-align: center;
    background: #fc6;
      }
    #container {
      margin: 0 auto 0 auto;
      width: 1000px;
      height:1000px;
      text-align: left;
    background: #ff0;
    position: relative;
      }
    
    #Layer1 {
    	position:absolute;
    	width:17px;
    	height:12px;
    	z-index:1;
    	left: 492px;
    	top: 22px;
    background: #00f;
    }
    #Layer2 {
    	position:absolute;
    	width:451px;
    	height:335px;
    	z-index:2;
    	left: 20px;
    	top: 21px;
    }
    #Layer3 {
    	position:absolute;
    	width:16px;
    	height:11px;
    	z-index:3;
    	left: 979px;
    	top: 22px;
    background: #ccc;
    }

    It's really too bad DreamWeaver seems to steer new coders toward using absolute positioning. Have a quick read on the Pitfalls of AP.
    It would be much better to float all your divs instead.

    Like this -
    Code:
    body {
    text-align: center;
    background: #fc6;
      }
    #container {
      margin: 0 auto 0 auto;
      width: 1000px;
    /*height:1000px;*/
    overflow: auto; /*to clear the floats*/
      text-align: left;
    background: #ff0;
      }
    
    #Layer1 {
    	width: 150px;
    /*height:12px;*/
    float: left;
    background: #00f;
    }
    #Layer2 {
    	width:451px;
    float: left;
    }
    #Layer3 {
    	width:250px;
    float: left;
    background: #ccc;
    }

    And last, when posting code in the forum, please use the code tags, &#91;code&#93;&#91;/code&#93; - available with the # button in the post edit window.
    This will wrap your code in a scroll box which greatly helps the readability of your post.
    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

  • #5
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Great, thanks a lot, that worked. I am still working through figuring out all that you are trying to tell me in the second part of the reply, so if I have any questions, I may ask, but you did help me fix the problem I had, so thank you very much. Mike

  • #6
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,675
    Thanks
    22
    Thanked 1,827 Times in 1,811 Posts
    Awesome. Always glad to help
    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


  •  

    Posting Permissions

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