CSS:显示差异

Jos*_*ein 5 css

display:block和display:inline有什么区别

apa*_*dit 11

display:block
将使对象强制容器内的其他对象进入新行.

display:inline
尝试在与其他对象相同的行上显示对象.

显示:块

Item 1 
Item 2 
Item 3

显示:内联

Item 1 Item 2 Item 3


小智 6

块元素通常垂直堆叠,而内联元素将水平排列.

两个Div将叠加在一起,但如果将它们设置为显示:inline,它们将水平相邻.与Span标签相反.


eth*_*eal 5

是的,

display:block 使元素表现得像块,例如:<p>

display:inline 使元素布局内联。

这些可以应用于默认为相反显示类型的元素。

可能的值

* none - no display at all.
* inline - An inline box.
* block - A block box.
* inline-block - effectively a block box inside an inline box. Not supported by Mozilla at time of writing. IE will only apply inline-block to elements that are traditionally inline such as span or a but not p or div. Loopy.
* run-in - Either an inline or block box depending on the context. If a block box follows the run-in box, the run-in box becomes the first inline box of that block box, otherwise it becomes a block box itself. Crazy. Not supported by IE/Win or Mozilla at the time of writing.
* list-item - the equivalent of the default styling of the HTML li element.
* table - a block-level table - the equivalent of the default styling of the HTML table element. Not supported by IE.
* inline-table - an inline-level table. Not supported by IE.
* table-row-group - the equivalent of the default styling of the HTML tbody element. Not supported by IE.
* table-header-group - the equivalent of the default styling of the HTML thead element. Not supported by IE.
* table-footer-group - the equivalent of the default styling of the HTML tfoot element. Not supported by IE.
* table-row - the equivalent of the default styling of the HTML tr element. Not supported by IE.
* table-column-group - the equivalent of the default styling of the HTML colgroup element. Not supported by IE.
* table-column - the equivalent of the default styling of the HTML col element. Not supported by IE.
* table-cell - the equivalent of the default styling of the HTML td or th elements. Not supported by IE.
* table-caption - the equivalent of the default styling of the HTML caption element. Not supported by IE.
Run Code Online (Sandbox Code Playgroud)

*来源