Why does break outside
when margin and padding is applied?

前端 未结 3 1610
礼貌的吻别
礼貌的吻别 2021-02-19 09:03

I know this is very basic CSS. How do I keep the span contained within the div? At the moment, the span extends outside the top and bottom of the div.

3条回答
  •  面向向阳花
    2021-02-19 09:22

    The vertical padding, border and margin of an inline, non-replaced box (e.g. span) start at the top and bottom of the content area, and has nothing to do with the 'line-height'. But only the 'line-height' is used when calculating the height of the line box. Therefore you see an overlapping here: http://jsfiddle.net/Q9AED/

    If you want to use a straightforward solution, you can use line-height rather than display: inline-block: using line-height.

    display: inline-block works in Safari >= 2, Opera >= 9, IE >= 8, Firefox > 3. But you can imitate an inline-block in IE < 8: display: inline; zoom: 1.

提交回复
热议问题