Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Center Align Website with Containment Layer  (Read 2906 times)

0 Members and 1 Guest are viewing this topic.

alence

    Topic Starter


    Greenhorn

    Center Align Website with Containment Layer
    « on: November 25, 2009, 11:46:35 PM »
    I am nearing completion of a website, and cannot remember the code to center the website in the browser window. I am using layers in Dreamweaver 8, and below is the code that I am using, but the website is still aligned on the left when I preview it. The website size is 800 pixels wide by 600 pixels tall.

    In the past I designed a website very similar to the one I am working on now, and I used Layer 0 as a containment layer (so this is what I am trying to do now).

    #Layer0 {
    position:absolute;
    left:50%;
    top:50%;
    width:800px;
    height:600px;
    margin-left:-400px;
    margin-top:-300px;
    z-index:0;
    }

    Thanks.

    kpac

    • Web moderator
    • Moderator


    • Hacker

    • kpac®
    • Thanked: 184
      • Yes
      • Yes
      • Yes
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 7
    Re: Center Align Website with Containment Layer
    « Reply #1 on: November 26, 2009, 10:32:36 AM »
    This is a problem many people run into.

    You need to create a seperate DIV around all your page content, just inside the body tag. Give it an id of "container".
    Now create a style for that div as follows:
    Code: [Select]
    div#container {
      width: 100%;
    }

    Then use the following style for your main page content:
    Code: [Select]
    div [???] {
      width: 800px;
      margin: auto;
    }

    It's basically setting the margin of your page's content to auto which does it but you need the container div for it to work.