CSS: 清除内联元素

CSS: clear on inline elements

检查这个 JSFiddle:

<IMG src="https://www.google.com.hk/images/srpr/logo11w.png" alt="This image will illustrate floats">
<span>The contents of floats are </span>

图像浮动,spanclear:both。但是,如果 span 的显示值为 inlineinline-block,则不会创建间隙。只有block,才会创建间隙

我检查了 Spec,它说:

both: Requires that the top border edge of the box be below the bottom outer edge of any right-floating and left-floating boxes that resulted from elements earlier in the source document.

它没有提到 display 如何影响许可的创建。有人可以帮忙解释一下吗?

很简单:clear 仅适用于块级元素。

'clear'

Applies to: block-level elements

Block-level elements 定义为

Block-level elements are those elements of the source document that are formatted visually as blocks (e.g., paragraphs). The following values of the display property make an element block-level: block, list-item, and table.