DEV Community


Discussion on: 4 CSS tricks that will get you dirty looks from other developers

ironydelerium profile image

The vertical padding one is actually a side effect of units in general: percentage units tend to be based on the width of the containing element when there is no other basis for determining them.

It's very handy for sizing things like a video player container so the page doesn't jump around while it loads, and also for making such players responsive.

Negative margins are one you have to be careful with, though - if you happen to have an element at the root of a scrolling container (including the main viewport) with negative horizontal margins, you will overflow in the horizontal direction resulting either in awkward horizontal scrollbars or, on a phone or tablet, a page that scrolls left/right without apparent reason.