Home > Article > Web Front-end > Comparison between div and span in HTML
This article mainly introduces the comparison between div and span in HTML, and introduces the usage and comparison of p and span respectively. Those who are interested can learn more
1. 8d5359d7acd57fbd757004226d27415dand45a2772a6b6107b401db3c9b82c049c254bdf357c58b8a65c66d7c19c8e4d114
1.e388a4556c0f65e1904146cc1a846bee94b3e26ee717c64999d7867364b1b4a3Tag
# The ##e388a4556c0f65e1904146cc1a846bee94b3e26ee717c64999d7867364b1b4a3 tag can define partitions or sections (pision/section) in the document, thereby dividing the document into independent and different parts. The e388a4556c0f65e1904146cc1a846bee94b3e26ee717c64999d7867364b1b4a3 tag can be used as a strict organizational tool and does not use any formatting associated with it, which contains the idea of separating HTML markup and presentation styles. In actual work, we usually specify the id or class attribute for the e388a4556c0f65e1904146cc1a846bee94b3e26ee717c64999d7867364b1b4a3 tag to make the tag more effective. e388a4556c0f65e1904146cc1a846bee94b3e26ee717c64999d7867364b1b4a3 is a block-level element, which means that its content automatically starts on a new line. And actually newlines are the only formatting behavior inherent in e388a4556c0f65e1904146cc1a846bee. The following HTML simulates the structure of a news website. Each pair of e388a4556c0f65e1904146cc1a846bee94b3e26ee717c64999d7867364b1b4a3 tags combines the title and summary of each news item. That is, e388a4556c0f65e1904146cc1a846bee94b3e26ee717c64999d7867364b1b4a3 adds additional structure to the document. At the same time, since these e388a4556c0f65e1904146cc1a846bee94b3e26ee717c64999d7867364b1b4a3 belong to the same type of elements, you can use the class="news" attribute to identify these e388a4556c0f65e1904146cc1a846bee94b3e26ee717c64999d7867364b1b4a3 tags. This not only provides e388a4556c0f65e1904146cc1a846bee 94b3e26ee717c64999d7867364b1b4a3 adds appropriate semantics and facilitates further use of styles to format e388a4556c0f65e1904146cc1a846bee94b3e26ee717c64999d7867364b1b4a3.<p class="news"> <h2> News headline 1</h2> <p> some text. some text. some text...</p> ... </p> <p class="news"> <h2> News headline 2</h2> <p> some text. some text. some text...</p> ... </p>
2.45a2772a6b6107b401db3c9b82c049c254bdf357c58b8a65c66d7c19c8e4d114Tags
45a2772a6b6107b401db3c9b82c049c2 Tags are used to group inline elements in the document.<span style="color: Red">注意:</span>
2. Block-level elements and inline elements
Block-level elements (block elements) and inline elements/inline elements (inline elements) ) is a concept in CSS. Elements like e388a4556c0f65e1904146cc1a846bee94b3e26ee717c64999d7867364b1b4a3 and 4a249f0d628e2318394fd9b75b4636b1473f0a7621bec819994bb5020d29372a are often called block-level elements. This is because these elements appear as a block of content, a "block box". In contrast, elements such as 45a2772a6b6107b401db3c9b82c049c254bdf357c58b8a65c66d7c19c8e4d114 and 8e99a69fbe029cd4e2b854e244eab143128dba7a3a77be0113eb0bea6ea0a5d0 are called "inline elements" because their content appears on a single line, an "inline box." The concepts of block-level elements and inline elements are not fixed, but relative. We can change the type of box generated using the element's display property. This means that you can make inline elements (such as 3499910bf9dac5ae3c52d5ede7383485 elements) behave like block-level elements by setting the display attribute to block; you can also make the generated elements become inline elements by setting display to inline; or even, We can set the display attribute to none so that the element has no box at all. In this case, the box and all its contents will no longer be displayed and will not occupy space in the document.<p id="dv1" style="display: block"> 我是一个块级元素。 </p> <p id="dv2" style="display: inline"> 我是一个行内元素。 </p> <p id="p3" style="display: none"> 我是不可见的 </p>
3. Comparison between e388a4556c0f65e1904146cc1a846bee94b3e26ee717c64999d7867364b1b4a3 and 45a2772a6b6107b401db3c9b82c049c254bdf357c58b8a65c66d7c19c8e4d114
1. Similarities: The e388a4556c0f65e1904146cc1a846bee94b3e26ee717c64999d7867364b1b4a3 tag and the 45a2772a6b6107b401db3c9b82c049c254bdf357c58b8a65c66d7c19c8e4d114 tag are tags used to divide intervals but have no actual semantics; both are mainly used to apply style sheets. 2. Difference: The e388a4556c0f65e1904146cc1a846bee94b3e26ee717c64999d7867364b1b4a3 tag is a block-level element, and the browser will automatically add a line break tag before and after it0b9f73f8e206867bd1f5dc5957dbcb38;45a2772a6b6107b401db3c9b82c049c227025bc3ef6ca249e01581ebe221e942 tag is an inline element, and newline tags will not be automatically added before and after it. If you want to display two pieces of content on the same line in a web page layout, the simplest way is to wrap them with 45a2772a6b6107b401db3c9b82c049c254bdf357c58b8a65c66d7c19c8e4d114 tags. For example, a page has two adjacent elements, one is e388a4556c0f65e1904146cc1a846bee94b3e26ee717c64999d7867364b1b4a3, the other is 45a2772a6b6107b401db3c9b82c049c254bdf357c58b8a65c66d7c19c8e4d114. To display them on the same line, change this e388a4556c0f65e1904146cc1a846bee94b3e26ee717c64999d7867364b1b4a3 to 45a2772a6b6107b401db3c9b82c049c254bdf357c58b8a65c66d7c19c8e4d114. Of course, this can also be achieved by setting the display attribute of tags such as e388a4556c0f65e1904146cc1a846bee94b3e26ee717c64999d7867364b1b4a3 to inline through CSS.Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.
Related recommendations:I will explain to you in detail how to create div in js through code, span, label
Discuss in detail the difference between display:inline style and span in div
How to define the minimum height of inline elementsspan
The above is the detailed content of Comparison between div and span in HTML. For more information, please follow other related articles on the PHP Chinese website!