Negative margins vs relative positioning

Yarin picture Yarin · Mar 10, 2011 · Viewed 13.1k times · Source

I've come across many layout techniques involving negative margins, such as this classic for sidebar positioning. It seems like these techniques could just as easily be applied with relative positioning.

So instead of this:

.sidebar {
    margin-left:-600px;
}

One would do this:

.sidebar {
    position:relative;
    left:-600px;
}

It seems like relative positioning might even be cleaner in the vertical direction, as top-margin manipulation may be affected by collapsing margin issues, etc.

Is there any advantage to one over the other, or are they practically equivalent?

Thanks-

Answer

anupam picture anupam · Mar 10, 2011

I guess relative positioning will shift the content to left but the original space will be occupied by it unless you make the next element relative too. However with negative margin the content and its original space both are shifted.