What is the difference between
margin-left: 10px; and position: relative; left: 10px;?
It seems to produce the same result
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
When you move something with
position:relativeyou’re not actually moving the space it takes up on the page, just where it is displayed.An easy way to test this is to use a simple structure like this:
with the following CSS:
versus this CSS:
You’ll see that the first moves everything down 50px while the second only moves the first image down (which means it will overlap the second image).
Edit: you can check it out in action here: http://www.jsfiddle.net/PKqMT/5/
Comment out the
position:relative;andtop:100px;lines and uncomment themargin-topline and you’ll see the difference.