Results 1 to 6 of 6

Thread: How to centre align a Div

  1. #1
    Join Date
    Nov 2005
    Posts
    132
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default How to centre align a Div

    Just learning the div tag and all I need to do is centre align it. Played around with left and right position but I'm a beginner and all i need is to center align it!

    Show me how silly I'm being, pease.

    Thanks.
    here's my div

    <div id=layer1 style="position:absolute; top:20; left:30%; width:300px; height:321px; z-index:1; padding:5px; border: #000000 2px solid; background-color:#6666ff;">
    Content goes here (images, text) </div>

  2. #2
    Join Date
    Mar 2006
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    i think u wanted to put the text stuffs in centre. did i get u? if so then for that the stuff i gess is quite simple.
    just put
    <center>
    .........
    ..........watever u want in center here...........
    .........
    </center>


    and it should come in centre. was that tough? lollllllllllllll

  3. #3
    Join Date
    Nov 2005
    Posts
    132
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Hi and thanks for your reply. I do seem to have grasped alignment of text within the div but I want to have my actual div layer centre aligned. I need it to move when the page is resized, so that it remains in the middle whatever the screen size is.
    Last edited by neilkw; 03-29-2006 at 10:05 AM.

  4. #4
    Join Date
    Nov 2005
    Posts
    132
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    This seems to have solved my problem

    http://www.bluerobot.com/web/css/center1.html

  5. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Misconception: <center>...</center> tags.... it's not really unique... but rather a shortcut for:
    <div align="center">...</div>

    If you want the actual layer to be alinged, you'll have to do more than that, 'cause that affects inside. You could do:

    <div align="center">
    <div>
    (this div is centered)
    </div>
    </div>

    Depends. You said you solved it. Hopefully this'll make it make more sense

  6. #6
    Join Date
    Nov 2005
    Posts
    132
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    cheers for your reply.

    I have achieved my desired placement by assigning the placement attributes via the style sheet. float left/right etc. Then assigning the div into the css.

Bookmarks

Posting Permissions

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