Aggravating CSS Centering

Discussion in 'HTML & Website Design' started by Ajay, Mar 11, 2007.

  1. #1
    I know this has been answered endlessly, but I just can't seem to make it work! Using Dreamweaver and layers, I want to center the design at http://www.davespetproducts.com.

    I think I understand the concept of placing everything in a container div and then using the text-align trick, but it's not working.
    I'd be really grateful for any suggestions on getting this to work! :eek:
     
    Ajay, Mar 11, 2007 IP
  2. tolra

    tolra Active Member

    Messages:
    515
    Likes Received:
    36
    Best Answers:
    1
    Trophy Points:
    80
    #2
    I had a quick look and I'm seeing a lot of position: absolute in your CSS, absolute positioning sets the elements a fixed distance from the top left of the browser window.

    Unless anyone has a bright idea I would redo the layout using relative positioning then you should be able to centre the layout without problem.
     
    tolra, Mar 11, 2007 IP
  3. Ajay

    Ajay Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks! I'll try that.
     
    Ajay, Mar 12, 2007 IP
  4. evenfall

    evenfall Well-Known Member

    Messages:
    145
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    108
    #4
    I agree that the layout should be redone. There are a ton of unnecessary divs here which complicates things.

    If you want to use absolute positioning, you could put everything you have into a container div with these styles: "margin-left: auto; margin-right: auto; width: 500px (replace this number with the actual width of the content); position: relative;"

    This will give you a container div which will stay centered. Any absolutely positioned div inside of the container will align itself with the edges of the container. Experiment with the "left" and "top" settings of your divs inside the container to get a feel for how this works.

    Hope that helps - it's much easier for me to do than to explain.
     
    evenfall, Mar 13, 2007 IP