What is the difference between div and span? Analysis and explanation

高洛峰
Release: 2017-03-06 17:19:29
Original
2021 people have browsed it

Ask what is the difference between p and SPAN? Many of my friends must have only a little knowledge of it. Here I can tell you that the biggest feature of the p and SPAN elements is that by default, no formatting is performed on the objects within the elements.

Question: What is the difference between p and SPAN? ?

Answer: Solution:

The biggest feature of the p and SPAN elements is that by default, the objects within the elements are not rendered in any format. Mainly used for applying style sheets. The most obvious difference between the two is that p is a block element, while SPAN is an inline element (also translated as inline element).

Specific steps:

1. The so-called block elements are elements that start rendering on a new line. Inline elements do not need to start on a new line. Test the following code and you will have a more vivid image. Understanding:
Test<span>Follow the previous "test" display</span><p>A new line will be displayed here</p>
2. Block elements and inline elements are not static. By defining CSS display attribute values ​​​​can be converted into each other, such as:
Test<p style="display:inline">Follow the previous "test" display</p><span style="display:block"> ;A new line will appear here to display
Tips: If you do not define any CSS attributes on the p element, the display effect will be on the P element.

Because of the particularity of p and SPAN elements, they are generally used to apply style sheets. For example, they are defined as layers using CSS. What needs to be distinguished is the difference between block elements and inline elements, as well as the differences between the two. Transform each other.

pSpecify the container for rendering HTML.
SPAN specifies an inline text container.
In general, a p occupies a block, and its default display attribute is block, indicating a block. For example:

aaa

bbb is displayed with two lines.
As for span, its default display attribute is inline and can be connected together. For example: aaabbb, displayed as one line.
p is generally used for typesetting, while span is generally used for partial text styling.

For more analysis and explanation of the difference between div and span, please pay attention to the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!