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
https://forums.phpfreaks.com/topic/271394-center-a-div-in-absolute-parent/
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.