Q: What is the difference between DIV and SPAN?
Answer: Solution:
The biggest feature of DIV and SPAN elements is that neither the default rendering of objects within the elements is done in any formatting. Mainly used to apply 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 an inline element).
Specific steps:
1. The so-called block element is an element that starts rendering with another line. The elements in the line do not need to start another line. Test the following code and you will have a more vivid understanding:
Test <span> Follow the previous test display </span> <div> Here will be a new line showing </div>
2. Block elements and in-line elements are not static. By defining the display attribute values of CSS, they can be converted to each other, such as:
Test <div style=display:inline>Follow the previous test display </div><span style=display:block>A new line will be displayed here </span>
Tip: If no CSS attribute is defined for the DIV element, its display effect will be on the P element.
Because of the particularity of DIV and SPAN elements, it is generally used to apply style sheets, such as using CSS as a layer, and what needs to be distinguished is the difference between block elements and in-line elements, and the mutual conversion between the two.
DIV specifies the container to render HTML.
SPAN specifies the embedded text container.
In general, a div occupies a block, and its default display property is block, representing a block. like:
<div>aaa</div>bb is displayed, and there are two lines.
As for span, its display default attribute is inline, which can be connected together. For example: <span>aaa</span>bb, it is displayed as a line.
div is generally used for typesetting, while span is generally used for styles of local text.