Strange margin issue with a display: inline-block child

前端 未结 4 1827
温柔的废话
温柔的废话 2020-12-19 17:19

Heres the fiddle

When I set #two to inline-block it subtracts the 16 px of top/bottom margin from the

and adds it to the divs c

4条回答
  •  有刺的猬
    2020-12-19 17:48

    This has already been answered and accepted, still I'd like to point out that clearfixing it would have prevented margin collapse thus normalizing its behaviour

    I'd add:

    .two:before,
    .two:after {
        content: " ";
        display: table; 
    }
    
    .two:after {
         clear: both;
    }
    

    See this fiddle . Here's the Nicholas Gallagher clearfix I've used.

提交回复
热议问题