CSS Float does not stretch Div Height

前端 未结 4 1814
慢半拍i
慢半拍i 2021-02-03 15:42

I have had this problem for a long time when working with HTML/CSS and Floats.

In the image you can see I have a Box Div that is Floated left as there is many of these B

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-03 15:50

    You need to clear your floats using a clearfix or clearing element.

    Method #1 clearfix

    .clearfix:before,
    .clearfix:after {
        content: " ";
        display: table;
    }
    
    .clearfix:after {
        clear: both;
    }
    
    .clearfix {
        *zoom: 1;
    }
    

    Then you add the class on the containing element

     

    http://jsfiddle.net/u5HXu/8/

    Method #2 Clearing Element

    .clear {
        clear: both;
    }
    

    Then you add the following HTML after your floated elements.

    http://jsfiddle.net/u5HXu/9/

提交回复
热议问题