Jump to content

centering


acidglitter

Recommended Posts

position:absolute is exactly that - no more no less - YOU tell it where to go regardless of the window ... it does not adjust with the rest of the page because position:absolute is OUTSIDE of the flow of your code markup flow..

 

Lose position:absolute. It is not a good layout tool.

 

Don't float or use "position", just give the div a width less than its container and use "margin: 0 auto"

Link to comment
Share on other sites

I know this isn't way your talking about, but here is a way to position something horizontally and vertically center:

#div
{
    position: absolute;
    margin: -100px 0 0 -100px;
    top: 50%;
    left: 50%;
    width: 200px;
    height: 200px;
}

Link to comment
Share on other sites

That will just make a mess of anything else on the page because position:absolute is greedy and ignores everything else.

 

Until you are an expert at css (not just "good enough", I'm talkin' you know it all cold) avoid position:absolute like the plague. It is NOT a "friendly" layout element and does NOT play well with others.

Link to comment
Share on other sites

well i don't want this div to have anything to do with the rest of the page. its a temporary div that i want to show up in the middle of the screen, no matter if you're at the top of the page or have scrolled down to the middle.. so i was just setting the position to absolute, then the top position to a certain amount of pixels plus however many pixels away from the top of the page.. i guess instead of top it would work the same to set that to margin-top and then the other margins to auto (and then a high z-index)...

Link to comment
Share on other sites

i guess instead of top it would work the same to set that to margin-top and then the other margins to auto (and then a high z-index)...

 

As simple as that.

 

You don't even need the z-index if it isn't being "absolute-positioned".

 

#div
{
    margin:25% auto 0 auto;
    width: 200px;
    height: 200px;
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.