Then I had one question in my head. Why on some sites someone uses margin-top for indents, and someone uses margin-bottom. What is better to use? enter image description here

enter image description here

Closed due to the fact that it is necessary to reformulate the question so that it was possible to give an objectively correct answer to the participants of HamSter , VenZell , pavel , aleksandr barakin , rjhdby 12 Oct '16 at 6:55 .

The question gives rise to endless debates and discussions based not on knowledge, but on opinions. To get an answer, rephrase your question so that it can be given an unambiguously correct answer, or delete the question altogether. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • 6
    Why sometimes scratch the back of his head with his right hand and sometimes his left? What is better to use? - Alexey Shimansky
  • Cool joke, I think you are not here. - spmpl
  • You have a question from the same series .... Apparently everything depends on the situation and the preference for only one thing is not the right choice. - Alexey Shimansky

3 answers 3

If I understand correctly, you ask how to make the spacing between adjacent elements: for this you can either set the margin-bottom top element, or the margin-top bottom.

Of course, there is no secret rule in this matter. Use what you prefer. The only thing to remember is the surrounding elements. Imagine that you have three blocks:

  1. No padding.
  2. Indented at the top and bottom.
  3. No padding.

If for some reason the second block disappears, the first and third blocks will merge. Sometimes this is the desired behavior, but most often not.

It would be better to do this:

  1. Indent from the bottom.
  2. Indent from the bottom.
  3. No padding.

Or so:

  1. No padding.
  2. Indent from the top.
  3. Indent from the top.

Thus, visually the page will not fall apart if any elements disappear from it. The main thing is to be consistent and logical in your choice. Well, remember that the elements can be visually level, and in the markup they can be nested in other elements. In this case, you may need to indent the wrapper, and not the elements themselves.

    It all depends on the task that the developer is facing. If you need an indent at the top, then you need to use the margin-top property; if you don’t do without an indent at the bottom, you should use margin-bottom

      The rule of good tone when using layout is margin-bottom , not margin-top .

      • one
        Andrew, can you indicate what this judgment is based on? For the first time I hear about this "rule of good tone". - VenZell
      • I support. There is such a "non-secret" rule. It is more correct to use margin-bottom . - HamSter
      • one
        If such a rule really exists (I have not heard about it either), it is necessary to clarify how it is justified. I can only explain this by the fact that we analyze the page from bottom to top, and the indentation is the last property in importance, but the counter arguments can be given exactly the same. - Alexey Ukolov
      • 2
        I'll tell you where the rule came from. With a code review, when there is some kind of conflict, in which the arguing parties have equal arguments, a lot of time is spent. To avoid this, all companies have their own code-style - a document with all the rules for writing code in their office. In the end, people get used to this style, forget about the document, and the rule becomes unspoken. By what principle is the rule formed if the arguments of the disputing parties are equal? Yes, just randomly. So another developer may well say that it is more correct to use the margin-top for a good tone - P. Ilyin
      • one
        @ElenaSemenchenko, if P.Ilyin is right, the rules adopted within the company cannot be an argument for a response, because it will be an answer based not on knowledge, but on opinion. - VenZell