That guilty feeling i get when I use negative margins

  • 0
    Yes, I agree with you.
  • 1
    We've all been there.
  • 2
    Sometimes . You just have to
  • 6
    I feel the same anytime I use !important
  • 0
    The only time I use negative margin is center aligning an absolute element.


    Although I hear there is a better way of doing it.
  • 0
    A second case for negative margin or the use of !important is when editing someone else's code. God does it drive me mad.
  • 0
    Setting a element to center

    .containElement {
    Position relative;
    .centeredele {

    The centerele must have width or height defined to center if you just want vertical don't use left or right if you want horizontal only don't use top bottom

    There is obviously flex now as well..

    You should never use, !important

    But in a rush and your working on someone code... It understandable. But literally no other reason
  • 0
    @FitzSuperUser that's one way of doing it, however I believe it will not work in the case of an overlay element say a pop up or a login box.

    I should've clarified the use of my code too hahaha
  • 0
    @uziiuzair no you can you just define Percentages
  • 1
    @FitzSuperUser ah yes, sorry my bad. I had something else in mind and then read your code again to figure it out!
  • 3
    Yes you should, I turn into the hulk when I see that. Just do left 50% and transform: translatex(-50%) Or better yet: flexbox ftw
  • 1
    @uziiuzair I should say the element inside needs position absolute
Add Comment