Overview and differences between html inline elements and html block-level elements

Overview and differences between html inline elements and html block-level elements
Block-level element features :
•Always occupies a line by itself, starting from a new line, and the elements that follow must also be displayed on a new line;
•Width, height, padding and margin can all be controlled;

Inline element properties :
• On the same line as adjacent inline elements;
• The width (width), height (height), top/bottom of the inner margin (padding-top/padding-bottom) and top/bottom of the outer margin (margin-top/margin-bottom) cannot be changed, that is, the size of the text or picture inside;

The main block-level elements are :

Copy code
The code is as follows:

address , blockquote , center , dir , div , dl , fieldset , form , h1 , h2 , h3 , h4 , h5 , h6 , hr , isindex , menu , noframes , noscript , ol , p , pre , table , ul

The main inline elements are :

Copy code
The code is as follows:

a , abbr , acronym , b , bdo , big , br , cite , code , dfn , em , font , i , img , input , kbd , label , q , s , samp , select , small , span , strike , strong , sub , sup ,
textarea , tt , u , var

Variable elements (determine whether the element is a block element or an inline element based on the context) :

Copy code
The code is as follows:

applet ,button ,del ,iframe , ins ,map ,object , script

Application of block-level and inline elements in CSS :
By using CSS, we can get rid of the restrictions of HTML tag classification in the table above and freely apply the attributes we need to different tags/elements.

The main CSS styles used are the following three :
•display:block -- Display as a block-level element
•display:inline -- Display as an inline element
• dipslay:inline-block -- Displayed as an inline block element, it is displayed in the same row and can modify properties such as width, height, inner and outer margins. We often add the display:inline-block style to the <ul> element, so that the originally vertical list can be displayed horizontally.

Off topic : I recently sorted out some knowledge about the difference between block-level elements and inline elements. I found a lot of related articles on the Internet and found that everyone's understanding seemed to be wrong. I tested it myself and found a lot of problems :
1. The margin-left / margin-right and padding-left / padding-right of inline elements can be controlled, so the width of inline elements can be controlled by these four properties.
2. Block-level element tags can also be placed inside inline elements, and the internal block-level element tags will expand the external inline tags, so the height of inline elements can be controlled by placing block elements (it is introduced on the Internet that inline elements can only hold text and other inline elements)
For example:

Copy code
The code is as follows:

<a>
<div style="width:100px;height:100px;">Test</div>
</a>

<<:  Detailed explanation of the benefits of PNG in various network image formats

>>:  Methods and steps to use http-proxy-middleware to implement proxy cross-domain in Node

Recommend

Zabbix monitors Linux hosts based on snmp

Preface: The Linux host is relatively easy to han...

How to use file writing to debug a Linux application

In Linux, everything is a file, so the Android sy...

Summary of common Nginx techniques and examples

1. Priority of multiple servers For example, if e...

How to solve the problem of clicking tomcat9.exe crashing

A reader contacted me and asked why there were pr...

MySQL 5.7 installation and configuration tutorial

This article shares the MySQL installation and co...

How to add conditional expressions to aggregate functions in MySql

MySQL filtering timing of where conditions and ha...

Solve the problem of Nginx returning 404 after configuring proxy_pass

Table of contents 1. Troubleshooting and locating...

How to write the style of CSS3 Tianzi grid list

In many projects, it is necessary to implement th...

Element uses scripts to automatically build new components

Table of contents background How does element-ui&...

JS realizes the calculation of the total price of goods in the shopping cart

JS calculates the total price of goods in the sho...

Solve the mysql user deletion bug

When the author was using MySQL to add a user, he...

CentOS 6.5 configuration ssh key-free login to execute pssh command explanation

1. Check and install pssh, yum list pssh 2. Becau...

Several ways to easily traverse object properties in JS

Table of contents 1. Self-enumerable properties 2...

Win10 + Ubuntu 16.04 dual system perfect installation tutorial [detailed]

Be sure to remember to back up your data, it is p...