Jump to content
Sign in to follow this  
thichtomo

Attribute position:relative doesn't work properly in firefox?

Recommended Posts

I have a piece of CSS as following (in order to align a div vertically center)

#center {	position:relative;	height:200px;	width:500px;	top:50%;	margin:-100px auto 0px auto;	border-radius:10px;	border:1px solid white;}

In Chrome, it works well, as in the first illustration:

 

chrome_div_vertical_align.png

 

but in Firefox, it's displayed as following:

 

firefox_div_vertical_align.png

 

Please, explain to me the reason of the issue. You can check this issue in your browser by link: http://thichtomo.com/example/

Share this post


Link to post
Share on other sites

Although I do not know exactly why browsers do not render it the same, the correct way to achieve this make the following changes in bold:

 

#center { border: 1px solid #FFFFFF; border-radius: 10px; height: 200px; left: 50%; margin: -100px 0 0 -250px; position: absolute; top: 50%; width: 500px;}

  • Like 1

Share this post


Link to post
Share on other sites

Although I do not know exactly why browsers do not render it the same, the correct way to achieve this make the following changes in bold:

 

#center { border: 1px solid #FFFFFF; border-radius: 10px; height: 200px; left: 50%; margin: -100px 0 0 -250px; position: absolute; top: 50%; width: 500px;}

If we use: position:absolute, it works well even in firefox. In my opinion, if we put margin-left and margin-right as auto, browsers will automatically set divs horizontally center.

Share this post


Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
Sign in to follow this  

×
×
  • Create New...