Basic concepts and usage examples of HTML inline elements and block-level elements

Basic concepts and usage examples of HTML inline elements and block-level elements

There are two types of html tags, inline elements and block-level elements. First, let's understand the concepts of inline elements and block-level elements:

Block-level elements: Generally, they are containers for other elements. They can hold inline elements and other block-level elements. Block-level elements exclude other elements from being on the same line as them. They can set width and height attributes. Block-level elements in the normal flow will be placed vertically. Common block elements are "div"

Inline elements (inline elements): Inline elements can only contain text or other inline elements. They are descendants of block-level elements. They allow other inline elements to be located on the same line with them. The height and width cannot be set. A common inline element is "a".

According to the concept of block-level elements, we can understand that block-level elements have line breaks before and after them, which is equivalent to adding a <br> tag before and after the element. We can think of block-level elements as a block or a rectangle, so block-level elements can set height and width attributes

example:
css file:

Copy code
The code is as follows:

#div1{
width:200px;
height:200px;
background:#666
}
div2{
width:200px;
height:200px;
background:#F00
}

html file:

Copy code
The code is as follows:

<div id="div1">
div1
Block-level elements exclude other elements from being placed on the same line as them
</div>
<div id="div2">
div2
Block-level elements exclude other elements from being placed on the same line as them
</div>

Display effect:

The two div elements are not on the same line

According to the concept of inline elements, we can understand that there are no line breaks before and after inline elements. We can think of an inline element as a line, so it cannot have height and width attributes set.

Block element tags

address - address
blockquote - Blockquote
center – align in the center
dir - directory listing
div - commonly used block-level element, and also the main tag of CSS layout
dl - Definition List
fieldset - form control group
form - interactive form
h1 - Large title
h2 - Subtitle
h3 - Level 3 heading
h4 - Level 4 heading
h5 - Level 5 heading
h6 - Level 6 heading
hr - horizontal separator line
isindex - input prompt
menu - menu list
noframes - frames optional content, (for browsers that do not support frames, this block content is displayed
noscript - optional script content (displayed for browsers that do not support script)
ol - Sorting Form
p - paragraph
pre - format text
table
ul - unordered list

Inline element

a - anchor point
abbr - abbreviation
acronym - first letter
b - bold (not recommended)
BDO - Bidi Override
big - large font
br - Line break
cite - citation
code - computer code (required when citing source code)
dfn - defines a field
em - emphasis
font - font settings (not recommended)
i - italic
img - picture
input
kbd - Define keyboard text
label - table label
q - short quote
s - hyphen
samp - define sample computer code
select - item selection
small - small font text
span - commonly used inline container, defines the text block
strike - a dash
strong - bold emphasis
sub - subscript
sup—superscript
textarea - multi-line text input box
tt - defines typewriter text
var - define a variable

<<:  Solutions for high traffic websites

>>:  CSS achieves the effect of hiding the scroll bar and scrolling the content (three ways)

Recommend

Linux parted disk partition implementation steps analysis

Compared with fdisk, parted is less used and is m...

CSS3 overflow property explained

1. Overflow Overflow is overflow (container). Whe...

mysql add, delete, modify and query basic statements

grammar Here is the generic SQL syntax for INSERT...

Example code of vue icon selector

Source: http://www.ruoyi.vip/ import Vue from ...

HTML unordered list bullet points using images CSS writing

Create an HTML page with an unordered list of at l...

HTML Tutorial: Collection of commonly used HTML tags (6)

Related articles: Beginners learn some HTML tags ...

Methods and steps for deploying multiple war packages in Tomcat

1 Background JDK1.8-u181 and Tomcat8.5.53 were in...

Analysis of MySQL example DTID master-slave principle

Table of contents 1. Basic Concepts of GTID 2. GT...

Sample code for CSS image animation effects (photo frame)

This article introduces the sample code of CSS pi...

Detailed Analysis of the Selection of MySQL Common Index and Unique Index

Suppose a user management system where each perso...

How to start Vue project with M1 pro chip

Table of contents introduction Install Homebrew I...

Css3 realizes seamless scrolling and anti-shake

question The seamless scrolling of pictures and t...