Is it a good practise to use negative margins to remove padding of wrapper element?
For example, which of the following code pieces is better to use?
<div style="padding: 5px;">
Shortened width string
<div style="margin: 0 -5px;">Full width string</div>
Shortened width string
</div>
or
<div>
<div style="padding: 5px;">Shortened width string</div>
<div>Full width string</div>
<div style="padding: 5px;">Shortened width string</div>
</div>
Why not just declare padding:5px 0;
so you don't have horizontal padding? Though I would argue that it's perfectly fine to use negative margins, that's what they're made for but if you can avoid them in the first place, do so.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With