将元素浮动到右边后无法清除元素

时间:2011-05-18 23:26:10

标签: html css css-float

我出于某种原因永远无法清除元素,只是为了让人困惑!我试试这个:

.clearfix:after {
        visibility: hidden;
        display: block;
        font-size: 0;
        content: " ";
        clear: both;
        height: 0;
        }
* html .clearfix             { zoom: 1; }  /*IE6*/ 
*:first-child+html .clearfix { zoom: 1; }  /*IE7 */

到父元素,没有任何作用!真的很混乱:/

http://pastebin.com/qAGaCYbH

2 个答案:

答案 0 :(得分:1)

您应该将.clearfix类应用于您的元素。我想你要清除#page-wrap。要将.clearfix类应用于该div,请写:<div id="post-wrap" class="clearfix">

答案 1 :(得分:1)

html5boilerplate.com

尝试此操作
/* The Magnificent Clearfix: 
   Updated to prevent margin-collapsing on child elements. 
   j.mp/bestclearfix */

.clearfix:before, .clearfix:after { 
    content: "\0020"; 
    display: block; 
    height: 0; 
    overflow: hidden; 
}

.clearfix:after { 
    clear: both; 
}

/* Fix clearfix: 
   blueprintcss.lighthouseapp.com/projects/15318/tickets/5-extra-margin-padding-bottom-of-page */

.clearfix { 
    zoom: 1; 
}