Home >Web Front-end >HTML Tutorial >How to convert block elements into other elements in html5

How to convert block elements into other elements in html5

青灯夜游
青灯夜游Original
2022-03-11 16:44:594307browse

Conversion method: 1. Add the "display:inline;" style to the block element to convert the block element into an inline element; 2. Add "display:inline-block;" to the block element. Block elements can be converted to inline block elements.

How to convert block elements into other elements in html5

The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.

Convert block elements in html5 to other elements (inline or inline block)

Block element characteristics:

  • (1) Able to identify width and height

  • (2) The upper, lower, left and right margins and padding are valid for it

  • (3) Can automatically wrap lines

  • (4) Multiple block element tags are written together, and the default arrangement is from top to bottom

Characteristics of inline elements:

  • (1) Setting width and height is invalid

  • (2) Setting margin is only valid in the left and right directions, but not up and down ; The padding setting is valid for both left and right, which means it will expand the space.

  • (3) It will not automatically wrap the line

Characteristics of block elements within the line :

  • (1) Does not automatically wrap

  • (2) Can recognize width and height

  • (3) The default arrangement is from left to right

In HTML5, you can use the display attribute to convert block elements into inline or inline block elements.

  • display:inline;Convert to inline element

  • display:inline -block;Convert to inline block elements

Example:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<style>
			p{
				background-color: #FFC0CB;
				height: 50px;
			}
		</style>
	</head>
	<body>
		<p>块状元素p</p>
		<p>块状元素p</p>
		<p style="display: inline;">块状元素p--转为行内元素</p>
		<p style="display: inline;">块状元素p--转为行内元素</p>
		<p>块状元素p</p>
		<p style="display: inline-block;">块状元素p--转为行内块元素</p>
		<p style="display: inline-block;">块状元素p--转为行内块元素</p>
	</body>
</html>

How to convert block elements into other elements in html5

As you can see, block Inline elements and inline block elements can set heights, but inline elements cannot; while inline elements and inline block elements do not wrap, block elements do.

【Related recommendations: html video tutorial, web front-end

The above is the detailed content of How to convert block elements into other elements in html5. 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