Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS help with css

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #46502
    sadunaresh
    Participant

    I am actually trying to apply “margin:0 auto ” to a absolutely positioned element with some z-index… and failed to bring to effect…

    actual css

    .abovemask {
    background-color: #FFFFFF;
    border: 4px solid #EAEAEA;
    margin: 0 auto;
    position: fixed;
    top: 200px;
    width: 800px;
    z-index: 5001;
    }

    can someone please explain me the reason and work-around will be appreciated…

    #143472
    sadunaresh
    Participant

    .abovemask {
    background-color: #FFFFFF;
    border: 4px solid #EAEAEA;
    margin: 0 auto;
    position: fixed;
    top: 200px;
    width: 800px;
    z-index: 5001;
    }

    #143473
    Kitty Giraudel
    Participant

    To put it simple, `margin: 0 auto` have no effect on absolute/fixed elements. To center such an element, you can do this:

    .element {
    width: 800px;
    position: fixed;
    left: 50%;
    margin-left: -400px; // minus half the width
    }

    #143483
    sadunaresh
    Participant

    @HugoGiraudel.. Thank you very much…

Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘CSS’ is closed to new topics and replies.