Home >Web Front-end >HTML Tutorial >What is the difference between div and span_HTML/Xhtml_Webpage Production

What is the difference between div and span_HTML/Xhtml_Webpage Production

WBOY
WBOYOriginal
2016-05-16 16:38:461380browse

Q: What is the difference between DIV and SPAN?

Answer: Solution:

The biggest feature of DIV 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 DIV 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><div>A new line will appear here</div>
2. Block elements and inline elements are not static. By defining the display attribute value of CSS, the values ​​can be converted into each other, such as:
Test<div style="display:inline">Follow the previous "test" display</div><span style="display:block"> ;A new line will appear here</span>
Tip: If you do not define any CSS attributes for the DIV element, its display effect will be the same as that of the P element.

Due to the particularity of DIV 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.

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

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

Statement:
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