The order in which the rendering tree is painted onto the canvas is described in terms of stacking contexts. Stacking contexts can contain further stacking contexts. A stacking context is atomic from the point of view of its parent stacking context; boxes in other stacking contexts may not come between any of its boxes.
加黑那句该如何翻译和理解?
需要层叠的元素是指那些z-index不为
auto
的元素(auto和0是不完全一样,根元素一定会生成一个层叠环境),一个需要层叠的元素会生成一个层叠环境,一个元素(准确说是层叠环境)把其中需要层叠元素(层叠环境)作为一个整体决定其前后关系。p
把a
b
分别作为一个整体决定其前后关系。根据a
b
的z-index,要么a
在整个b
元素的前面,要么在后面,而(黑体文字的意思是)a
不会出现在b1
b2
之间。对于
b
中的两个元素来说,a
就是在其他层叠环境中的(other stacking contexts),他不应该出现在b1
和b2
之间。这是因为b
的z-index不为auto,所以b作为一个需要层叠的元素会生成新的一级层叠环境,他作为一个整体决定和a
的前后关系。因此,a
不会出现在b1
b2
之间。如果
b
的z-index为 auto,则b
不生成层叠环境,这时a
b1
b2
实在同一个层叠环境中,a
可以在b1
b2
之间