zhangxinxu / cssworld

《CSS世界》三部曲答疑反馈交流区
49 stars 2 forks source link

【答疑】《CSS世界》-44-幽灵空白节点疑问 #14

Open HuangYaobin opened 2 years ago

HuangYaobin commented 2 years ago
<div><span></span></div>
span { display: inline-block; }

为什么这里的span一定要设置display: inline-block,此时幽灵空白节点才会撑开div的高度呢?

HuangYaobin commented 2 years ago

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.

原文:https://www.w3.org/TR/CSS2/visuren.html#inline-formatting

是因为行框盒子没有创建,所以没有幽灵空白节点?

niusz commented 2 years ago

为什么不回答一下呢

AlwaysLucky commented 1 year ago

我也疑问为什么要设置这个

HuangYaobin commented 1 year ago

我也疑问为什么要设置这个

可以看看这个 https://segmentfault.com/q/1010000014296346