For what reason margin collapse rules were introduced in CSS?

后端 未结 3 1094
梦毁少年i
梦毁少年i 2020-12-03 07:17

Just can\'t figure out the situation when this clever set of rules can be helpful. They break the simplicity of the box model and provide infinite source of troubles when yo

3条回答
  •  一向
    一向 (楼主)
    2020-12-03 08:11

    When it could be helpful?

    The simplest example: a list of paragraphs and headings, each with a margin-top and margin-bottom. You want a margin on the top and bottom of the article, and between different elements.

    With margin collapsing, you can do without setting special margins on the first or last item (NOT a part of the original CSS spec!) or padding the container.

    But I agree, on a whole, it's a pointless feature.

提交回复
热议问题