Home Web Front-end HTML Tutorial Detailed summary of HTML tag nesting rules suitable for novice friends_HTML/Xhtml_Web page production

Detailed summary of HTML tag nesting rules suitable for novice friends_HTML/Xhtml_Web page production

May 16, 2016 pm 04:36 PM
html tag

I have been re-learning HTML recently, which can be regarded as a new understanding of HTML! Don't underestimate this thing, all web pages are based on it! Let’s summarize the nesting rules of HTML tags in detail. I hope it will be helpful to everyone.

There are many XHTML tags: div, ul, li, dl, dt, dd, h1~h6, p, a, addressa, span, strong... When we use these tags to build the page structure, They can be nested infinitely, but nesting also needs to have certain rules, and you cannot allow your own personal habits to be nested randomly - XHTML is not XML after all.

In the language of XHTML, we all know: ul tag contains li, dl tag contains dt and dd - the nesting rules of these fixed tags are very clear. However, there are still many tags that are independent and not bundled together, such as h1, div, p... So what are the nesting rules of these tags? Let’s talk about this topic today.

When it comes to the nesting rules of XHTML tags, we first need to know that there are two types of XHTML tags:
One type is called block-level elements (block)
The other type is called inline elements (inline, Many people also call it: inline, inline, line level, etc.)

The standard for dividing block-level elements and inline elements is very simple. Please put the following two lines of code into the body tag:

Copy code
The code is as follows:

div1

div2



Browser rendering effect:
div1
div2

The two divs presented on the page occupy two rows of space. Unless they are floated or other settings are made, no one is next to each other. They are both domineering. occupies its own row of space - whenever you see this phenomenon in a tag, you can call it: block-level element (block);

Then put the following two lines of code into the body tag Here:

Copy code
The code is as follows:

span1
span2


Browser rendering effect:
span1 span2

This time, the two spans are juxtaposed in a row. They are friendly, friendly and harmonious... With label behavior like this, we You can call them: inline elements;

The difference between block-level elements and inline elements:

·Block-level elements are generally used to build website architecture, layout, and carry content... …These major physical tasks are all block-level elements, which include the following tags:

address, blockquote, center, dir, div, dl, dt, dd, fieldset, form, h1~h6, hr , isindex, menu, noframes, noscript, ol, p, pre, table, ul

· Inline elements are generally used in certain details or parts of website content to "emphasize, distinguish styles, Superscript, subscript, anchor point, etc., the following tags are all inline elements:

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


· Block element and inline elements can be converted to each other. The conversion code is as follows:
display: block; /* Convert to block element*/
display: inline; /* Convert to inline element*/

· The CSS calling rules for block elements and inline elements are different (this article discusses tag nesting, so this knowledge point will not be explained).

After briefly understanding block elements and inline elements, the nesting rules of XHTML tags can be listed below:

1. Block elements can contain inline elements or certain block elements. But inline elements cannot contain block elements, they can only contain other inline elements:

—— Yes
—— Yes
< ;/span> —— Wrong

2. Block-level elements cannot be placed inside

:

  1. —— Wrong

    —— Wrong

    3. There are several special block-level elements It can only contain inline elements and can no longer contain block-level elements. These special tags are:
    h1, h2, h3, h4, h5, h6, p, dt

    4. inside li Can contain div tags - This item does not need to be listed separately, but many people on the Internet are confused about this, so I will briefly explain it here:

    Li and div tags are both containers for loading content and have equal status. , there is no level distinction (for example: strict hierarchies such as h1 and h2^_^). You must know that the li tag can even accommodate its parent ul or ol. Why do some people think that li cannot accommodate a div? Woolen cloth? Don't think that li is so stingy. Even though li looks quite thin, in fact, li has a big heart...

    5. Block-level elements are juxtaposed with block-level elements, and inline elements are inline with inline elements. Juxtaposition:

    —— Right
    —— Right

    < ;/div> —— Wrong
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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

How to extract HTML tag content using regular expressions in Go language How to extract HTML tag content using regular expressions in Go language Jul 14, 2023 pm 01:18 PM

How to use regular expressions to extract HTML tag content in Go language Introduction: Regular expression is a powerful text matching tool, and it is also widely used in Go language. In the scenario of processing HTML tags, regular expressions can help us quickly extract the required content. This article will introduce how to use regular expressions to extract the content of HTML tags in Go language, and give relevant code examples. 1. Introduce related packages First, we need to import related packages: regexp and fmt. regexp package provides

How to remove HTML tags using Python regular expressions How to remove HTML tags using Python regular expressions Jun 22, 2023 am 08:44 AM

HTML (HyperTextMarkupLanguage) is a standard language for creating Web pages. It uses tags and attributes to describe various elements on the page, such as text, images, tables, links, etc. However, when processing HTML text, it is difficult to quickly extract the text content for subsequent processing. At this time, we can use regular expressions in Python to remove HTML tags to quickly extract plain text. In Python, regular tables

How to remove HTML tags from string in PHP? How to remove HTML tags from string in PHP? Mar 23, 2024 pm 09:03 PM

PHP is a commonly used server-side scripting language that is widely used in website development and back-end application development. When developing a website or application, you often encounter situations where you need to process HTML tags in strings. This article will introduce how to use PHP to remove HTML tags from strings and provide specific code examples. Why do you need to remove HTML tags? HTML tags are often included when processing user input or text obtained from a database. Sometimes we want to remove these HTML tags when displaying text

How to escape html tags in php How to escape html tags in php Feb 24, 2021 pm 06:00 PM

In PHP, you can use the htmlentities() function to escape html, which can convert characters into HTML entities. The syntax is "htmlentities(string,flags,character-set,double_encode)". You can also use the html_entity_decode() function in PHP to de-escape html and convert HTML entities into characters.

How to remove HTML tags from given string in Java? How to remove HTML tags from given string in Java? Aug 29, 2023 pm 06:05 PM

String is a final class in Java, it is immutable, which means we cannot change the object itself, but we can change the reference of the object. HTML tags can be removed from a given string using the replaceAll() method of String class. We can remove HTML tags from a given string using regular expressions. After removing the HTML tags from the string, it returns a string as normal text. Syntax publicStringreplaceAll(Stringregex,Stringreplacement) example publicclassRemoveHTMLTagsTest{&nbs

How to use HTML tags in HTML tables? How to use HTML tags in HTML tables? Sep 08, 2023 pm 06:13 PM

We can easily add HTML tags in the table. HTML tags should be placed inside <td> tags. For example, add paragraph <p>…</p> tags or other available tags inside the <td> tag. Syntax The following is the syntax for using HTMl tags in HTML tables. <td><p>Paragraphofthecontext</p><td>Example 1 An example of using HTML tags in an HTML table is given below. <!DOCTYPEhtml><html><head&g

PHP regular expression method to verify basic HTML tags PHP regular expression method to verify basic HTML tags Jun 24, 2023 am 08:07 AM

PHP is an efficient web development language that supports regular expression functions and can quickly verify the validity of input data. In web development, HTML is a common markup language, and validating HTML tags is a very important method for web form validation. This article will introduce basic HTML tag verification methods and how to use PHP regular expressions for verification. 1. Basic structure of HTML tags HTML tags consist of element names and attributes surrounded by angle brackets. Common tags include p, a, div

Complete collection of HTML tags Complete collection of HTML tags Nov 27, 2023 am 10:05 AM

HTML标签有<!DOCTYPE>、<html>、<head>、<title>、<meta>、<link>、<style>、<script>、<body>、<h1> - <h6>、<p>、<a>、<img>、<div>、<span>、<input>、<button>、<form

See all articles