CSS规范的一点疑问

Line boxes are created as needed to hold inline-level content within an inline formatting context. Line boxes that contain no text, no preserved white space, no inline elements with non-zero margins, padding, or borders, and no other in-flow content (such as images, inline blocks or inline tables), and do not end with a preserved newline must be treated as zero-height line boxes for the purposes of determining the positions of any elements inside of them, and must be treated as not existing for any other purpose.

不太理解上面引用的规范,有人能解释下么?

阅读 2.1k
2 个回答

Line boxes are created as needed to hold inline-level content within an inline formatting context. Line boxes that contain no text, no preserved white space, no inline elements with non-zero margins, padding, or borders, and no other in-flow content (such as images, inline blocks or inline tables), and do not end with a preserved newline must be treated as zero-height line boxes for the purposes of determining the positions of any elements inside of them, and must be treated as not existing for any other purpose.

第一句,意思是,line boxes 的创建是为了容纳和定位其中的inline-level元素。

第二句,去掉斜体的定语,意思是,对于"不包含内容"的(不包含xx,xx,xx...上面斜体所说的那些)line box,存在的目的仅仅是为了定位其中的元素,并且此时这个line box 的高度为0。 除此之外,不应该以其他任何目的创建一个"不包含内容"的line box

给你个例子,absolute 是基于 containing block 定位的,span 影响了定位,且看不到蓝色,说明 span 存在一个零高的 line box 里。

<style>
p {
  position: relative;
  background: red;
  padding: 10px;
}

span {
  position: relative;
  background: blue;
}

i {
  position: absolute;
  top: 0;
  left: 0;
}
</style>

<p>
  <span><i>absolute</i></span>
</p>
  
<p>
  <i>absolute</i>
</p>
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题