The only replaced elements are those that embed external content, such as an image, video, applet, or HTML5 canvas into an HTML document.
Normal flow
Block formatting contexts
Inline formatting contexts
Relative positioning
Floating a box
Absolute positioning
display值为flex或者inline-flex的元素将会生成自适应容器(flex container)
A block container box that contains no block-level boxes.
Block Formatting Contexts就是页面上的一个隔离的渲染区域
float的值不为none。
overflow的值不为visible。
absolutely positioned elements ( absolute or fixed)
display的值为table-cell, table-caption, inline-block。
The adjoining margins of two or more boxes can combine to form a single margin. Margins that combine this way are said to collapse.
折叠的结果: 两个相邻的外边距都是正数时,折叠结果是它们两者之间较大的值。 两个相邻的外边距都是负数时,折叠结果是两者绝对值的较大值。 两个外边距一正一负时,折叠结果是两者的相加的和。
元素的margin-top与其第一个常规文档流的子元素的margin-top
元素的margin-bottom与其下一个常规文档流的兄弟元素的margin-top
height为auto的元素的margin-bottom与其最后一个常规文档流的子元素的margin-bottom
高度为0并且最小高度也为0,不包含常规文档流的子元素,并且自身没有建立新的BFC的元素的margin-top和margin-bottom
创建了新的BFC的元素(例如浮动元素或者'overflow'值为'visible'以外的元素)与它的子元素的外边距不会折叠
一个常规文档流元素的margin-top 与其第一个常规文档流的子元素的margin-top产生折叠,条件为父元素不包含 padding 和 border ,子元素不包含 clearance。
闭合浮动的元素的border-top会紧贴着相应的浮动元素的margin-bottom。
自适应宽度是指当未明确设定容器的宽度(或margin设为auto)时,在特定的情况下容器的宽度会根据情况自行设定,而设定的结果往往并不是我们想要的。
几种Shrink-to-fix的情况
对于浮动或者特殊的定位方式,推荐显式的设置容器宽度,避免出现意想不到的结果
min(max(preferred minimum width, available width), preferred width)