What is the difference between div and span? _ HTML/Xhtml _ webpage Creation

Source: Internet
Author: User
Q: What is the difference between DIV and SPAN? Many of my friends may be confused. Here, we can tell you that the biggest feature of the DIV and SPAN elements is that they do not perform any formatting and rendering on the objects in the Elements by default. Q: what is the difference between DIV and SPAN?

Answer: solution:

The biggest feature of DIV and SPAN elements is that they do not perform any formatting and rendering on objects in the element by default. It is mainly used to apply a style sheet. The most obvious difference between the two is that DIV is a block element, while SPAN is a line element (also translated as an embedded element ).

Procedure:

1. The so-called block element is the element that starts rendering with another line. The element in the line does not need to start with another line. You will have a better understanding of the Code below the test example:
Test <span> display next to test </span> <p> A new line is displayed. </p>
2. Block elements and intra-row elements are not static. They can be converted to each other by defining the display attribute values of CSS, for example:
Test <p style = "display: inline"> test </p> <span style = "display: block "> A new line is displayed here </span>
Tip: If no CSS attribute is defined for the DIV element, the display effect will be displayed on the P element.

Because of the particularity of DIV and SPAN elements, it is generally used to apply style sheets. For example, CSS is used as a layer. What needs to be distinguished is the difference between block elements and intra-row elements, there is also a mutual conversion between the two.

DIV specifies the HTML Rendering container.
SPAN specifies the embedded text container.
In general, a p occupies a block, and its default display attribute is block, indicating a block. For example:

Aaa

The bbb shows two rows.
Span, whose display attribute is inline by default, can be connected together. For example, aaabbb shows a row.
P is generally used for typographical layout, while span is generally used for partial text styles.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.