SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru
    Join Date
    Jun 2009
    Posts
    792
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    z-index on centered elements..

    hi,

    how can you apply z-index to centered elements (z-index only works with positioned elements; positioned elements can't be centered... whether I center with margin:0 auto; or with text-align:center in containing element (body in my case); as soon as I apply position:relative; or position:absolute; it won't be centered anymore...)

    thank you..

  2. #2
    SitePoint Addict sdleihssirhc's Avatar
    Join Date
    Feb 2009
    Posts
    387
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    It looks like there's more going on to mess up the centering than you explained. Here's a fiddle that shows a centered element can have position/z-index. Can you post the actual HTML/CSS, or link to a live example?
    I'm the web overlord for Graphic Business Systems

  3. #3
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    23,616
    Mentioned
    413 Post(s)
    Tagged
    7 Thread(s)
    I second sdleihssirhc's comment that there is something else going on here. As sdleihssirhc's nice example shows, position: relative doesn't affect the element's centering at all.

  4. #4
    The CSS Clinic is open silver trophybronze trophy
    Paul O'B's Avatar
    Join Date
    Jan 2003
    Location
    Hampshire UK
    Posts
    39,868
    Mentioned
    159 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by maya90 View Post
    hi,

    how can you apply z-index to centered elements (z-index only works with positioned elements; positioned elements can't be centered... whether I center with margin:0 auto; or with text-align:center in containing element (body in my case); as soon as I apply position:relative; or position:absolute; it won't be centered anymore...)

    thank you..
    No, as the others have said position:relative on its own will not affect centering at all (unlike position:absolute) and will allow the z-index to be applied..


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
  •