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

Solve the problem of VScode configuration remote debugging Linux program

Let's take a look at the problem of VScode re...

Use iframe to submit form without refreshing the page

So we introduce an embedding framework to solve th...

Multiple ways to change the SELECT options in an HTML drop-down box

After the form is submitted, the returned HTML pag...

Docker container custom hosts network access operation

Adding the extra_hosts keyword in docker-compose....

Several ways to clear arrays in Vue (summary)

Table of contents 1. Introduction 2. Several ways...

Detailed example of jQuery's chain programming style

The implementation principle of chain programming...

Secondary encapsulation of element el-table table (with table height adaptation)

Preface During my internship at the company, I us...

uniapp Sample code for implementing global sharing of WeChat mini-programs

Table of contents Create a global shared content ...

Web page experience: planning and design

1. Clarify the design direction <br />First,...

Vue implements infinite loading waterfall flow

This article example shares the specific code of ...

More popular and creative dark background web design examples

Dark background style page design is very popular...

How to automatically import Vue components on demand

Table of contents Global Registration Partial Reg...

JavaScript to implement retractable secondary menu

The specific code for implementing the retractabl...

MySQL8.0.18 configuration of multiple masters and one slave

Table of contents 1. Realistic Background 2. Agre...