Home >Web Front-end >HTML Tutorial >Detailed explanation of the differences between inline elements, block-level elements and empty elements

Detailed explanation of the differences between inline elements, block-level elements and empty elements

迷茫
迷茫Original
2017-03-25 15:37:491913browse

Inline elements: a, b, span, img, input, strong, select, label, em, button, textarea

Block-level elements: p, ul, li, dl, dt, dd, p , h1-h6, blockquote

Empty elements: br, meta, hr, link, input, img

Characteristics of block-level elements:

1. Always starts on a new line and occupies a whole line
2. By default, its width automatically fills the width of its parent element
3. The width is always the same as the browser width, regardless of the content
4. It can accommodate inline elements and other block elements
5. The display attribute is block

The vertically adjacent margins of block-level elements will be merged.

Characteristics of inline elements:

1. All on the same line as other elements
2. High, line height and margins and padding parts can be Change
3. The width is only related to the content
4. Inline elements can only accommodate text or other inline elements
5. The display attribute is inline

horizontal padding-left, padding- Right, margin-left, and margin-right all produce margin effects,
but vertical padding-top, padding-bottom, margin-top, and margin-bottom do not produce margin effects.
The width and height cannot be set. The width increases with the content, and the height changes with the font size. Inline elements can set outer boundaries, but the outer boundaries do not affect the top and bottom, but only the left and right.

Characteristics of empty elements:

HTML content without content is called an empty element. Empty elements are closed in the opening tag.

is an empty element without a closing tag (
tag definition wraps).
In XHTML, XML, and future versions of HTML, all elements must be closed.
Adding a slash in the opening tag, such as
, is the correct way to close an empty element, and is accepted by HTML, XHTML, and XML.
Even though
is valid in all browsers, using
is actually a longer-term guarantee.

The above is the detailed content of Detailed explanation of the differences between inline elements, block-level elements and empty elements. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn