Is there a rule or guideline for writing CSS that should use margin or padding to add indents?


This question is a translation of " When to use margin vs padding in CSS "

  • Hmm, did you add the disclaimer yourself, is the question a translation, or is the site system automatically? - Stanislav Belichenko
  • @ Stanislav himself added. Click the "edit" button and look at the markup. - Vadizar
  • Yes, I have already looked, but still decided to ask, because I do not understand the meaning of this action. - Stanislav Belichenko
  • one
    @ Stanislav translate good questions and answers - you can. meta.ru.stackoverflow.com/questions/4224/…. I hope that the esteemed Vadizar now translates the answers too =) - Duck Learns to Hide
  • @ Duck Teaches Mind, something not in a hurry :) - Stanislav Belichenko

1 answer 1

It is you and your designer who decide. Everything depends on the design. There are really rules in different css frameworks. But this is not something unique and unified.
So, in general, use padding for indentation inside the block, margin for omitting the block itself.
Again, depending on the pattern (or mood), you can not use these rules at all.

  • the difference is clear, but are there any principles, for example, for a block indent from another block that does not have a border and the difference between the external and internal buy-out will not be visible. How to be in such cases? - Vadizar
  • as you describe, for example, bootstrap works: in the bootstrap grid, there are no margins between cells by default, only padings and due to this a visual gap is reached between them. - Kirill Korushkin