CSS:文档流

CSS的文档流介绍。

官网:https://www.w3.org/TR/2016/WD-CSS22-20160412/visuren.html#normal-flow。

文档流

文档流其实应该叫正常流,英文是Normal flow,我的理解呢,就是接收到的文档的内容,因为这些内容一直从服务端传输过来,边传输边需要处理,就像水流一样,所以称为流。

在文档流中的盒子是需要归属于一个上下文的,块级盒子参与到块格式化上下文中,内联级盒子参与到内联格式化上下文中,还有表格格式化上下文。

块格式化上下文(Block formatting contexts)

块格式化上下文,简称BFC,是按照从上到下,一个一个垂直排列的,块之间的间距是靠margin来控制的。

In a block formatting context, boxes are laid out one after the other, vertically, beginning at the top of a containing block. The vertical distance between two sibling boxes is determined by the ‘margin’ properties. Vertical margins between adjacent block-level boxes in a block formatting context collapse.

翻译:在块格式化上下文中,框从一个包含块的顶部开始一个接一个地垂直排列。 两个兄弟盒子之间的垂直距离由“margin”属性决定。 块格式化上下文中相邻块级盒子之间的垂直margin会折叠。

##内联格式化上下文(Inline formatting contexts)
内联格式化上下文,简称IFC,主要是水平排列的,水平对齐是由一些参数来控制的。

An inline formatting context is established by a block container box that contains no block-level boxes. In an inline formatting context, boxes are laid out horizontally, one after the other, beginning at the top of a containing block. Horizontal margins, borders, and padding are respected between these boxes. The boxes may be aligned vertically in different ways: their bottoms or tops may be aligned, or the baselines of text within them may be aligned. The rectangular area that contains the boxes that form a line is called a line box.

翻译:内联格式化上下文由不包含块级框的块容器盒子建立。 在内联格式化上下文中,盒子从一个接一个地开始,从一个包含块的顶部开始。 这些框之间会考虑水平边距,边框和填充。 盒子可以以不同的方式垂直对齐:它们的底部或顶部可以对齐,或者它们内的文本的基线可以对齐。 包含形成一条线的框的矩形区域称为线盒子line box

这里面有一些父容器和子布局的一些关系,需要梳理。

相对定位

相对定位是根据这个盒子原本在文档流中的位置或者floated进行一些偏移。

未完,待续……