BFC layout rules and trigger conditions

1. The meaning of BFC:         

  

                               Block Formatting Contexts (BFC) block-level element formatting contexts

                                It determines how a block-level element lays out its content, as well as its relationship to and interrelationships with other elements

                                block-level element: parent (is a block element)

                                content: child element (is a block element)

                                Other elements: sibling elements at the same level as the content

                                Interaction: elements in the BFC will not affect the elements outside              

 

                 2. Trigger condition:      

      

                            

                                  The way to trigger BFC (click any one)

                                        1. The value of float is not none

                                        2. The value of overflow is not visible

                                        3. The value of display is one of table-cell, tabble-caption and inline-block

                                        4. The value of position is not static or any of relative

 

                3. The difference between FBC layout and ordinary document flow layout      

                              

                     Normal document flow layout rules

                      1. Floating elements are not calculated by their parent height

                      2. Non-floating elements will override the position of floating elements

                      3.margin will be passed to the parent

                      4. The upper and lower margins of two adjacent elements will overlap

    

                            BFC layout rules

                            1. Floating elements will be calculated height by the parent (the parent triggers the BFC)

                            2. Non-floating elements will not cover the floating element position (non-floating elements trigger BFC)

                            3.margin is not passed to the parent (the parent triggers the BFC)

                            4. The upper and lower margins of two adjacent elements will overlap (add a parent to one of the elements, and then let his parent trigger BFC)

  1. <divstyle="border:1px solid #f00;overflow:hidden; ">
  2. <divstyle="width:100px; height:100px; background:green;float:left;">kaivon</div>
  3. </div>
  4. <divstyle="border:1px solid #f00;margin-top:100px; ">
  5. <divstyle="width:100px; height:100px;background:green;float:left;">kaivon1</div>
  6. <divstyle="width:100px; height:100px;background:red;overflow:hidden;">kaivon2</div>
  7. </div>
  8. <divstyle="background:blue;margin-top:100px;overflow:hidden;">
  9. <divstyle="width:100px; height:100px; background:green; margin-top:100px;">kaivon1</div>
  10. <divstyle="width:100px; height:100px; background:red;">kaivon2</div>
  11. </div>
  12. <divstyle="margin-top:100px; border:1px solid red;">
  13. <divstyle="width:100px; height:100px; background:green;margin:100px0;">kaivon1</div>
  14. <divstyle="overflow:hidden;">
  15. <divstyle="width:100px; height:100px; background:red;margin:100px0;">kaivon2</div>
  16. </div>
  17. </div>
                  How overflow is displayed for content beyond the parent
 
                  visible Default value, the content beyond that will be displayed
                  auto If the content exceeds the parent, then the scroll bar appears, if the content does not exceed, then the scroll bar does not appear
                  hidden beyond the content to hide              
                  scroll scrollbar appears regardless of whether the content exceeds  
 

                            

 

 
 
 
 
 

1. The meaning of BFC:         

  

                               Block Formatting Contexts (BFC) block-level element formatting contexts

                                It determines how a block-level element lays out its content, as well as its relationship to and interrelationships with other elements

                                block-level element: parent (is a block element)

                                content: child element (is a block element)

                                Other elements: sibling elements at the same level as the content

                                Interaction: elements in the BFC will not affect the elements outside              

 

                 2. Trigger condition:      

      

                            

                                  The way to trigger BFC (click any one)

                                        1. The value of float is not none

                                        2. The value of overflow is not visible

                                        3. The value of display is one of table-cell, tabble-caption and inline-block

                                        4. The value of position is not static or any of relative

 

                3. The difference between FBC layout and ordinary document flow layout      

                              

                     Normal document flow layout rules

                      1. Floating elements are not calculated by their parent height

                      2. Non-floating elements will override the position of floating elements

                      3.margin will be passed to the parent

                      4. The upper and lower margins of two adjacent elements will overlap

    

                            BFC layout rules

                            1. Floating elements will be calculated height by the parent (the parent triggers the BFC)

                            2. Non-floating elements will not cover the floating element position (non-floating elements trigger BFC)

                            3.margin is not passed to the parent (the parent triggers the BFC)

                            4. The upper and lower margins of two adjacent elements will overlap (add a parent to one of the elements, and then let his parent trigger BFC)

  1. <divstyle="border:1px solid #f00;overflow:hidden; ">
  2. <divstyle="width:100px; height:100px; background:green;float:left;">kaivon</div>
  3. </div>
  4. <divstyle="border:1px solid #f00;margin-top:100px; ">
  5. <divstyle="width:100px; height:100px;background:green;float:left;">kaivon1</div>
  6. <divstyle="width:100px; height:100px;background:red;overflow:hidden;">kaivon2</div>
  7. </div>
  8. <divstyle="background:blue;margin-top:100px;overflow:hidden;">
  9. <divstyle="width:100px; height:100px; background:green; margin-top:100px;">kaivon1</div>
  10. <divstyle="width:100px; height:100px; background:red;">kaivon2</div>
  11. </div>
  12. <divstyle="margin-top:100px; border:1px solid red;">
  13. <divstyle="width:100px; height:100px; background:green;margin:100px0;">kaivon1</div>
  14. <divstyle="overflow:hidden;">
  15. <divstyle="width:100px; height:100px; background:red;margin:100px0;">kaivon2</div>
  16. </div>
  17. </div>
                  How overflow is displayed for content beyond the parent
 
                  visible Default value, the content beyond that will be displayed
                  auto If the content exceeds the parent, then the scroll bar appears, if the content does not exceed, then the scroll bar does not appear
                  hidden beyond the content to hide              
                  scroll scrollbar appears regardless of whether the content exceeds  
 

                            

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324938499&siteId=291194637