A brief discussion of the difference between block elements and inline elements

青灯夜游
Release: 2019-11-30 17:28:32
forward
3049 people have browsed it

Tag elements in HTML are generally divided into three different types: block elements, inline elements (also called inline elements) and inline block elements. So what is the difference between block elements and inline elements? Let me introduce it to you below.

A brief discussion of the difference between block elements and inline elements

##Inline elements

In html, , , Tags such as and

are typical inline elements. Of course, block elements can also be displayed as inline elements by setting

display:inline;, so that block-level elements have the characteristics of inline elements.

p{
  display:inline;
}
...<p>我要变成内联元素!</p>
Copy after login

Characteristics of inline elements:

1. On the

same line as other elements, not on an exclusive line;

2. The height, width and top and bottom margins of elements

cannot be set;

(ps: the top and bottom margins of inline elements, margin-top and margin-bottom attributes do not work , and the margin-left and margin-right attributes can work. The padding attributes top, bottom, left, and right can also work,

but the padding-top attribute can only reach the top of the browser at most , padding- top is higher than the top of the browser, and the element will not move down. When adding a background to an inline element, you can use padding, but the background color will cover the surrounding elements.)

3. The width of the element is the image contained in the element. Or the width of the text, which cannot be set;

*: Gaps will appear when there are "carriage returns", "tabs", and "spaces" between inline elements.

Solution: Write it on one line, without spaces, carriage returns or other symbols in the middle.

Block elements

In html

,

,

,
,

Related labels:
source:cnblogs.com
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!