Jump to content

[SOLVED] Absolute position with auto margins?


fanfavorite

Recommended Posts

What I am trying to do is set a div outside of all other divs that will always be just right of my page.  I don't want it to effect anything on the page, so I am using absolute positioning.  This works in IE7, but not in Firefox or Safari so far.  Firefox and Safari ignore the margin auto and just place the div left:0px.  Any ideas how to make sure that these browsers center it? 

 

#sitetype {

position:absolute; 

margin:0px auto;

top: 34px; 

width:831px;

text-align:right;

}

 

Thanks. 

Make sure you've used {position:relative;} on the element that you're looking to position relative to.

 

The fact that {margin:0 auto;} is working in IE7 must be down to a bug in that browser. Since you're using a fixed width you should be able to "center" the div like this:

 

#sitetype {
position:absolute;
top: 34px;
left:50%; /*will position the left corner of the div at the mid-point of the div it is being positioned relative to*/
width:831px;
margin-left:-415px; /*will pull your div half its own width back towards the left*/

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.