overflow:hidden on div tag affects background color

后端 未结 2 643
时光取名叫无心
时光取名叫无心 2021-01-21 01:40

The definition of overflow:hidden states that :

the overflowing content is completely hidden, not accessible to the user.

from: http://

2条回答
  •  终归单人心
    2021-01-21 02:05

    That's because overflow: hidden affects margin collapse.

    p elements have some vertical margin by default. According to the spec, it collapses with the margin of the parent div:

    In CSS, the adjoining margins of two or more boxes (which might or might not be siblings) can combine to form a single margin. Margins that combine this way are said to collapse, and the resulting combined margin is called a collapsed margin.

    Adjoining vertical margins collapse, except [... not relevant]

    [... The] top margin of a box and top margin of its first in-flow child [are adjoining]

    However, overflow: hidden prevents that:

    Margins of elements that establish new block formatting contexts (such as floats and elements with overflow other than visible) do not collapse with their in-flow children.

提交回复
热议问题