Html block-level elements and embedded Elements

Source: Internet
Author: User

Example:
Put the following two lines of code into the body tag:
<Div style = "border: 1px solid red;"> div1 </div>
<Div style = "border: 1px solid red;"> div1 </div>
The rendering effect of the browser:
Div1
Div1
These two divs occupy two rows of space, called block-level elements ).
Put the following two lines of code into the body tag:
<Span style = "border: 1px solid red;"> span1 </span>
<Span style = "border: 1px solid red;"> span2 </span>
The rendering effect of the browser:
Span1 span1
These two spans are tied in one row, called inline ).

Differences between block-level elements and embedded elements:
· Block-level elements are used to build website architecture, layout, and carry content, such as div, ul, li, dl, dt, dd, h1-h6, p, address ......
Inline elements are used to modify a row in text, such as a, span, strong, sub, sup, img ......
· The block-level element is a box, and the box is wide or high. No matter how many items are in the box, you can set its width and height externally.
The Inline element is a bag, and its width and height are supported by the inside.
· The code for converting block-level elements and embedded elements is as follows:
Display: block;/* convert to block element */
Display: inline;/* convert to embedded elements */
· CSS calling rules for block-level elements and embedded elements:
1. A block element can contain inline elements or some block elements, but an inline element cannot contain block elements. It can only contain other inline elements:
<Div> <A href = "#"> <span> </a> --
<Span> <div> </span> -- Error
2. There are several special block-level elements that can only contain embedded elements, but cannot contain block-level elements. These special labels are:
H1-h6, p, dt.
<P> <ol> <li> </ol> </p> -- Error
<P> <div> </p> -- Error
3. li can contain div labels, parent ul or ol
Both li and div labels are content-loaded containers with equal status and no level.
4. Parallel Block-level elements and block-level elements, parallel embedded elements and embedded elements:
<Div> <Div> <a href = "#"> </a> <span> </div> --
<Div>

Related Article

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.