Summary-illustration and BFC illustration

Source: Internet
Author: User

Summary-illustration and BFC illustration

View me(Success. Fail) fail.Figure 1: Problem Diagram 2: Code diagram 3: solution Diagram

View me◔ ‸ ◔QuestionQuestion DiagramAndThe difference between solving the graph: The line of code with the yellow arrow does not have


BFC Definition

The BFC (Block formatting context) literal translation is "Block-level formatting context ". It is an independent rendering area with only Block-level box involved. It specifies how the internal Block-level Box is laid out and has nothing to do with the outside of the area.

BFC layout rules BFC creation method BFC solves problems

1. The maigin-top parent element and the margin-top child element collapse:

☞"The vertical distance of a Box is determined by margin. The margin of two adjacent boxes belonging to the same BFC overlaps."Rule 2: Cause

PS: You can also set border or padding.

2. Brother 1margin-BottomWith brother 2margin-TopCollapse:

☞"The vertical distance of a Box is determined by margin. The margin of two adjacent boxes belonging to the same BFC overlaps."Rule 2: Cause

3. Child element float-> parent element height collapse:

☞"When calculating the BFC height, floating elements are also involved in calculation."Rule 6: Solution

4. Brother 1float-> brother 2:

☞"The left side of the margin box of each element is in contact with the left side of the border box containing the block, even if there is a floating."Rule 3: Cause

☞"The BFC region does not overlap with the float box."Rule 4: Solution


BFCIs an isolated independent container on the page. The child elements in the container do not affect the external elements. And vice versa."Rule 5

BecauseBFCThe internal and external elements will never affect each other. Therefore, whenBFCWhen there is a floating outside, it should not be affectedBFCInternal Box layout,BFCIt will narrow down without overlap with the floating. Similarly, whenBFCWhen there is a floating inside, in order not to affect the layout of external elements,BFCThe calculated height includes a floating height. This is also the case for avoiding the overlap of margin.


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