Using :after to clear floating elements

后端 未结 5 938
失恋的感觉
失恋的感觉 2020-11-29 19:57

I have a list and the li\'s have a float:left;. The contents after the

    should be aligned correctly. Therefore i can build the following:
5条回答
  •  [愿得一人]
    2020-11-29 20:40

    This will work as well:

    .clearfix:before,
    .clearfix:after {
        content: "";
        display: table;
    } 
    
    .clearfix:after {
        clear: both;
    }
    
    /* IE 6 & 7 */
    .clearfix {
        zoom: 1;
    }
    

    Give the class clearfix to the parent element, for example your ul element.

    Sources here and here.

提交回复
热议问题