Jump to content

Center A Div In Absolute Parent


newbornultra

Recommended Posts

Hi,

I have to center a div in an absolute parent div.

 

The usual suspect giving a width and adding margin:0 auto doesn't work. It "sorta" works if I put left:25% in the div I'm trying to center, but it doesn't adjust if I resize the screen.

 

How do I do this?

 

<div id="rest">
<div class="wrap-reset">
 some content in center..
</div>
</div>

 

.wrap-reset
{
width:960px;
position:relative;
margin:0px;
}
#rest
{
position:absolute;
top:0px;
}

 

Thanks,

Link to comment
Share on other sites

Firstly I'd always style elements in the order the are set in html. So for instance, put your #rest css code above the .wrap_reset class declaration.

 

About your question, not too sure with absolute positioning but came across this example: http://jsfiddle.net/brettdewoody/C4jSS/

 

Hope it helps.

 

Regards,

 

AoTB.

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.