Home  >  Article  >  Web Front-end  >  A brief discussion of the difference between block elements and inline elements

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

青灯夜游
青灯夜游forward
2019-11-30 17:28:323073browse

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>

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

,

,

,
,

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete