Is negative margin bad practice? [closed]

4

Using a margin with negative value is a bad practice?

Example:

margin-top: -3px;
    
asked by anonymous 09.03.2017 / 19:52

2 answers

2

No, negative CSS margin is not bad practice. Negative margin is a great way to deny paddings in an element, when some inner element should be positioned in such a way.

Also, I think that the only 100% reliable way, supported by all browsers, to centralize an element vertically and horizontally in relation to a parent element, is to use negative margins, as follows:

.classe_css{
  left:50%;
  top:50%;
  position: relative;
  margin-left:-40px; /* -1/2 width */
  margin-top:-40px; /* -1/2 height */
}
    
09.03.2017 / 20:05
0

negative Margin is not necessarily a bad practice, for example you can use the faux-columns technique without images.

  

Negative values for margin properties are allowed, but there may be implementation-specific limits.

- W3C, about margin properties

This excerpt was taken from an iMasters discussion on the same subject.

Read this article here , it explains ways to use negative margins, showing common shapes, and errors too.

    
09.03.2017 / 20:00