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. 

Link to comment
Share on other sites

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*/

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.