Which clearfix method?

前端 未结 3 1866
温柔的废话
温柔的废话 2021-01-03 00:11

/* Clear Fix */

.clearfix:after {content: \".\";display:block;height:0;clear:both;visibility:hidden;}
* html .clearfix {height:1%;}

or

相关标签:
3条回答
  • 2021-01-03 00:28

    Most succinct technique is setting overflow:hidden for modern browsers:

    overflow:hidden;
    zoom:1;
    

    If an element needs to flow out of the dimensions ( negative margins or positioning ) then clearfix:

    #el:after { content:""; clear:both; display:block; visibility:hidden; }
    

    For IE6 and below, you need to trigger hasLayout ( through a width, zoom:1, height, and other property/value combos ). Starting with IE7, overflow will clear the floats.

    0 讨论(0)
  • 2021-01-03 00:41

    The latter seems to be fine because it also considers IE6 (zoom:1;).

    0 讨论(0)
  • 2021-01-03 00:44

    This has always worked for me. Very similar to yours

    .clearfix:after {
        content: "."; 
        display: block;
        height: 0; 
        font-size:0;
        clear: both; 
        visibility:hidden;
    }
        .clearfix{display: inline-block;}
        * html .clearfix {height: 1%;}
        .clearfix {display:block;}
    
    0 讨论(0)
提交回复
热议问题