need help to use DIV layer!

Discussion in 'CSS' started by sanchyclub, Oct 11, 2010.

  1. #1
    Hi,
    I need help.
    look at the code:

    <div id="layer1" style="position: absolute; left: 50px; top: 50px; width: 300px;
    height: 100px; z-index: 1">
    </div>

    I need to use div layer at center of the screen, so that when a user trying browse my site from normal screen monitor or extra width screen monitor it will show at center for both screen. where can i put the code for 'align'? please let me know with a valid code.
    thanks,
     
    sanchyclub, Oct 11, 2010 IP
  2. jmiles

    jmiles Peon

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    you can center a div using this code

    margin 0 auto;
    width: 300px;
     
    jmiles, Oct 11, 2010 IP
  3. sanchyclub

    sanchyclub Well-Known Member

    Messages:
    625
    Likes Received:
    6
    Best Answers:
    2
    Trophy Points:
    105
    #3
    thanks for the support but it not showing correctly at the center! Please check the code once again-

    <div id="layer1" style="position: absolute; left: 50px; top: 50px; margin 0 auto; width: 300px; height: 100px; z-index: 1" class="style2">
    </div>
     
    sanchyclub, Oct 12, 2010 IP
  4. GWiz

    GWiz Peon

    Messages:
    359
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    0
    #4
    GWiz, Oct 12, 2010 IP
  5. david.rew1164

    david.rew1164 Peon

    Messages:
    55
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    try using margin: auto;
     
    david.rew1164, Oct 13, 2010 IP
  6. GWiz

    GWiz Peon

    Messages:
    359
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    0
    #6
    He already has margin:auto, the problem isn't that, it's the fact that he still has left:50;. My instructions above are the solution to his problem.
     
    GWiz, Oct 13, 2010 IP
  7. sanchyclub

    sanchyclub Well-Known Member

    Messages:
    625
    Likes Received:
    6
    Best Answers:
    2
    Trophy Points:
    105
    #7

    Yes I got it...thanks
     
    sanchyclub, Oct 13, 2010 IP