Home Web Front-end HTML Tutorial What are the display modes of html block-level tags, inline tags, and inline block tags?

What are the display modes of html block-level tags, inline tags, and inline block tags?

Jan 22, 2018 am 11:09 AM
html Label

This time I will bring to you what are the display modes of html block-level tags, inline tags, and inline block tags. Notes on using html block-level tags, inline tags, and inline block tag display modesare Which ones, the following are practical cases, let’s take a look.

In today’s lecture, we talked about the display mode of tags in HTML, which are roughly divided into block-level tags and inline tags. Then when beginners first use tags, they will find that some attributes do not work on some tags, such as width, height, horizontal centering, etc. In fact, the use of this attribute only works on block-level tags. Personally, I think this is something that beginners can easily overlook, so I wrote it down!

For example, there will be a situation where horizontally centering the p tag has an effect, but adding a horizontally centered attribute to the font has no effect (as follows):

p{ color:red; text -align:center;}
font{color:red; text-align:center;}

I am a block-level tag p


I am an inline tag font

After running the preview, p can center the text horizontally, but font cannot

Then the above problem is related to the display in html It’s about the mode:

Characteristics of the display mode:

Mainly divided into two categories:

Block-level elements: occupy one line, take effect on the width and height attribute values; if If no width is given, the block-level element will default to the width of the browser, that is, 100% width;

Inline elements: multiple labels can exist on one line, and the width and height attribute values ​​will not take effect, and will be completely supported by the content. Width Height!

There is also a display mode that combines the advantages of the two modes:

Inline block element: The combined inline and block-level advantages can not only take effect on the width and height attribute values, but also more Each tag is displayed in one line;

The display mode in HTML is divided into block level and in-line. The commonly used block levels are: p, p, h1~h6, ul, li, dl, dt, dd.. . Commonly used inline elements include: span, font, b, u, i, strong, em, a, img, input, where img and input are inline block elements.

Then some students will think, can’t I control the width and height of span or font? Okay, so let’s put aside floating and positioning this time, and let’s convert them to each other through the display attribute:

1、块级标签转换为行内标签:display:inline;
2、行内标签转换为块级标签:display:block;
3、转换为行内块标签:display:inline-block;
Copy after login

Just give the corresponding tag Using this display attribute and taking the corresponding value, you can convert the display modes to each other.

I have said before whether the text-align attribute is effective. The reason is that if the block-level tag is not given a width, the block-level element will default to the width of the browser, which is 100% wide. Then at 100 The centering of the width of % takes effect; but the width of the inline element is completely stretched by the content, so the width is the width of the content. Let's give a background test to see:

So the block level is centered in the middle of the box However, because the width of the inline element is the width of the content and there is no space for centering, text-align:center; has no effect; but it will be different if the font is converted to block level:

p{ background:green; color:red; text-align:center;}    
font{background:green;color:red; text-align:center;display:block;}
Copy after login

Same as Reason, if the block level is converted to inline, the text cannot be displayed in the center.

Because in HTML, inline elements are regarded as tags with text properties. The block level can center the text horizontally. Then the inline tags at the block level are regarded as text properties. Then use text at the block level. -align:center;, the inline tags inside will be horizontally centered like text in the block-level tags:

Without text-align:center;:

p{ padding:5px;background:green; color:red;}    
font{ background:yellow;}    
<p>    
    <font>我是行内标签font</font> <font>我是行内标签font</font>    
</p>
Copy after login

With text -align:center;After

p{ padding:5px;background:green; color:red;text-align:center;}    
font{ background:yellow;}
Copy after login

I believe you have mastered the methods after reading these cases. For more exciting information, please pay attention to other related articles on the php Chinese website!

Related reading:

Basic knowledge of HTML, detailed introduction to the style of hyperlink settings

Basic knowledge of HTML .Detailed introduction to css style sheets and style attributes

How to use the href attribute of the HTMLa tag to specify relative paths and absolute paths

The above is the detailed content of What are the display modes of html block-level tags, inline tags, and inline block tags?. For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Table Border in HTML Table Border in HTML Sep 04, 2024 pm 04:49 PM

Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

Nested Table in HTML Nested Table in HTML Sep 04, 2024 pm 04:49 PM

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

HTML margin-left HTML margin-left Sep 04, 2024 pm 04:48 PM

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

HTML Table Layout HTML Table Layout Sep 04, 2024 pm 04:54 PM

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

HTML Input Placeholder HTML Input Placeholder Sep 04, 2024 pm 04:54 PM

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

HTML Ordered List HTML Ordered List Sep 04, 2024 pm 04:43 PM

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

Moving Text in HTML Moving Text in HTML Sep 04, 2024 pm 04:45 PM

Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.

HTML onclick Button HTML onclick Button Sep 04, 2024 pm 04:49 PM

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.

See all articles