SitePoint Sponsor

User Tag List

Results 1 to 9 of 9

Thread: Div question

  1. #1
    SitePoint Wizard dragonfly_7456's Avatar
    Join Date
    Dec 2002
    Location
    Moscow, USSR
    Posts
    1,092
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Div question

    How would I get a div to position ITSELF, not the contents withit it, in the center of the screen?
    Content Writing Service - Get custom SEO articles for 10$

  2. #2
    killall -9 lusers
    Join Date
    Oct 2002
    Location
    Cincinnati, Ohio, USA
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you give it an absolute width and set the left & right margins to 'auto', it should center up for you:

    Code:
    #centerblock {
        width:400px;
        margin-left: auto;
        margin-right: auto;
    }
    
    ------------------------------------------
    
    <div id="centerblock">This text should be aligned according to the inherited value for this element.</div>
    That question frustrated me for quite some time as well.

  3. #3
    SitePoint Wizard dragonfly_7456's Avatar
    Join Date
    Dec 2002
    Location
    Moscow, USSR
    Posts
    1,092
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How about making an invisible div the size of the entire screen (100%) and then having another div inside it with the desired size and centered. Worked for me

    Code:
    <div align="center" style="position:absolute; width:100%>
      <div style="position:absolute; width:745px;">
      </div>
    </div>
    Of course, you should have the styles in a different file. (.css), duh...
    Content Writing Service - Get custom SEO articles for 10$

  4. #4
    SitePoint Wizard dragonfly_7456's Avatar
    Join Date
    Dec 2002
    Location
    Moscow, USSR
    Posts
    1,092
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    AND I AM NOT A NEWBIE!
    Content Writing Service - Get custom SEO articles for 10$

  5. #5
    gingham dress, army boots... silver trophy redux's Avatar
    Join Date
    Apr 2002
    Location
    Salford / Manchester / UK
    Posts
    4,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    take your medication, dragon...you're talking to yourself again
    re·dux (adj.): brought back; returned. used postpositively
    [latin : re-, re- + dux, leader; see duke.]
    WaSP Accessibility Task Force Member
    splintered.co.uk | photographia.co.uk | redux.deviantart.com

  6. #6
    killall -9 lusers
    Join Date
    Oct 2002
    Location
    Cincinnati, Ohio, USA
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by dragonfly_7456
    How about making an invisible div the size of the entire screen (100%) and then having another div inside it with the desired size and centered. Worked for me

    Code:
    <div align="center" style="position:absolute; width:100%>
      <div style="position:absolute; width:745px;">
      </div>
    </div>
    It depends on how you want your code to validate. IIRC, the align attribute is deprecated in XHTML. This means you would actually have to set the 'text-align' property to 'center' on the outer div, and then you would have to reset it to 'left' on the inner div because of inheritance rules. I also believe there is an issue with one of the major browsers when you do it this (text-align) way (sorry, I can't remember which off the top of my head.)

  7. #7
    SitePoint Wizard dragonfly_7456's Avatar
    Join Date
    Dec 2002
    Location
    Moscow, USSR
    Posts
    1,092
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dang it... You can't remember? Well, it can't be IE, can it?
    Content Writing Service - Get custom SEO articles for 10$

  8. #8
    SitePoint Wizard dragonfly_7456's Avatar
    Join Date
    Dec 2002
    Location
    Moscow, USSR
    Posts
    1,092
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    And it can't be Netscape 7, tested already...

    If it is NS4 I'm not even bothering ... What a peice of crap that browser is... I think that is where netscape lost the majority of their users.
    Content Writing Service - Get custom SEO articles for 10$

  9. #9
    SitePoint Wizard dragonfly_7456's Avatar
    Join Date
    Dec 2002
    Location
    Moscow, USSR
    Posts
    1,092
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by redux
    take your medication, dragon...you're talking to yourself again
    Hehehe, no, I said that because KillAllDash9 had his little thing saying: "You_ARE_a newbie" ... he changed it now... I'm happy
    Content Writing Service - Get custom SEO articles for 10$


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
  •