CSS margin strange behavior, why?

前端 未结 3 577
天命终不由人
天命终不由人 2021-01-20 08:11

Having the HTML below


&l         


        
相关标签:
3条回答
  • 2021-01-20 08:48

    if you want to have the desired effect you can use "padding" instead, margins always collapse

    0 讨论(0)
  • 2021-01-20 08:51

    That behavior is called collapsing margins. The margin values are not added but the higher value is used:

    Vertical margins may collapse between certain boxes:

    • Two or more adjoining vertical margins of block boxes in the normal flow collapse. The resulting margin width is the maximum of the adjoining margin widths. […]
    • […]
    0 讨论(0)
  • 2021-01-20 08:54

    Here is a good explanation of margin collapsing. Basically, it seems that all adjacent margins will collapse into each other, per the CSS specification and against all common sense.

    0 讨论(0)
提交回复
热议问题