Div with display block 导致 inline-block parent 越界

Div with display block causes the inline-block parent to get out of line

我想了解这种奇怪的行为,我有一个 div 包装另一个 div。 parent 是显示内联块,而 child 是显示 none 或内部块,每当 child 是块时 - parent 从行中向下走,请参阅下面的例子: 这是在 child 中显示 none:

这是显示块

添加 parent 的 CSS:

谁能解释一下这种行为?

使用display:inline-block时,加上vertical-align:top;

display:block 将元素推到新行。当您说子项的显示是 none 时,它会尝试使元素与其他元素内联。因此观察到这种行为。

Check this link for detail on display property of css