带显示块的SPAN [英] SPAN with display block
问题描述
默认的< div>
元素和默认的< span>
元素之间有什么区别 display:block
?
What is the difference between the default <div>
element and the default <span>
element with display: block
?
推荐答案
有效性方面有所不同和HTML元素的语义。否则它们是相同的。
There is a difference with regards to validity and semantics of HTML elements. Otherwise they are identical.
-
div
和span
都定义为通用容器,在HTML方面没有更深的含义。一个默认为阻止显示,另一个默认为内联,因为这是两个主要组,几乎所有其他元素都属于
div
andspan
are both defined as generic containers without deeper meaning in terms of HTML. The one defaulting to block display, the other to inline, since these are the two major groups where almost any other element falls into
某些元素 包含在定义为块的元素中。这与CSS display
属性无关,但与HTML的语义有关:总体思想是基于内联始终是块的子代(也就是说,如果您认为
Certain elements must be contained by an element that is defined as a block. This has nothing to do with the CSS display
property, but with the semantics of HTML: The general idea is based on inlines being always children of blocks (which is, if you think of it, a good idea in general)
现在,如果您的 span
和 display:block
,就CSS而言,它的作用就像 div
一样。但是,从语义的角度来看,如果将块级元素嵌入 span
内,则将创建无效的HTML,因为您将块嵌套在嵌入式元素中。
Now, if you have a span
with display:block
, it will, in the sense of CSS, act exactly like a div
. However, from the semantic point of view, if you embed block level elements inside the span
, you are creating invalid HTML, because you nest a block in an inline element.
这篇关于带显示块的SPAN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!