Forums

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

Home Forums CSS Centering Ab. Positioned div

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #25440
    EamonnMac
    Member

    Sinking feeling about this one…

    Is there any way to automatically center an absolutely positioned div of dynamic width on the page? Any way at all?

    #60537
    eXo
    Member

    you mean a div that is positioned at the center? :?

    Code:
    body, html{
    width: 100%;
    height: 100%;
    }
    div{
    width: 75%;
    margin-left: auto;
    margin-right: auto;

    something like this?

    #60535
    TheDoc
    Member

    I’m not particularly sure why you’d want to do it (relative position not viable?), but looks like some people have had success with this one:

    http://www.zachgraeve.com/2006/10/01/ce … ition-div/

    #60524
    EamonnMac
    Member

    Thanks guys, both of those would work but both solutions require a fixed width to be applied to the centered div. In my case, I’m removing an image from a WP post and positioning it to the center of the top of the screen. To achieve this, I have to use absolute positioning, or the text in the post will leave a large gap to accommodate where it would have gone by default. What I’m aiming for is a way to do this for any size of image, automatically. To be honest I don’t think I can, but someone might know a way…

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