欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

CSS 浮動(dòng)清理,不使用 clear:both標(biāo)簽

 更新時(shí)間:2008年07月23日 19:48:39   作者:  
CSS:浮動(dòng)清理,不使用 clear:both標(biāo)簽 在進(jìn)行浮動(dòng)布局時(shí),大多數(shù)人都深知,在必要的地方進(jìn)行浮動(dòng)清理:<div style="clear:both;"></div>。
例如:
        <div style="background:#666;"> <!-- float container -->
                <div style="float:left; width:30%; height:40px;background:#EEE; ">Some Content</div>
        </div>
此時(shí)預(yù)覽此代碼,我們會(huì)發(fā)現(xiàn)最外層的父元素float container,并沒(méi)有顯示。這是因?yàn)樽釉匾蜻M(jìn)行了浮動(dòng),而脫離了文檔流,導(dǎo)致父元素的height為零。
若將代碼修改為:
        <div style="background:#666;"> <!-- float container -->
                <div style="float:left; width:30%; height:40px;background:#EEE; ">Some Content</div>
                <div style="clear:both"></div>
        </div>
注意,多了一段清理浮動(dòng)的代碼。這是一種好的CSS代碼習(xí)慣,但是這種方法增加了無(wú)用的元素。這里有一種更好的方法,將HTML代碼修改為:
        <div  class="clearfix" style="background:#666;"> <!-- float container -->
                <div style="float:left; width:30%; height:40px;background:#EEE; ">Some Content</div>
        </div>
定義CSS類,進(jìn)行“浮動(dòng)清理”的控制:
復(fù)制代碼 代碼如下:

.clearfix:after {}{
  content: ".";
  clear: both;
  height: 0;
  visibility: hidden;
  display: block;
}            /* 這是對(duì)Firefox進(jìn)行的處理,因?yàn)镕irefox支持生成元素,而IE所有版本都不支持生成元素 */
.clearfix {}{
  display: inline-block;     
}                /* 這是對(duì) Mac 上的IE瀏覽器進(jìn)行的處理 */
/**//* Hides from IE-mac \*/
* html .clearfix {}{height: 1%;}        /* 這是對(duì) win 上的IE瀏覽器進(jìn)行的處理 */
.clearfix {}{display: block;}        /* 這是對(duì)display: inline-block;進(jìn)行的修改,重置為區(qū)塊元素*/
/**//* End hide from IE-mac */ 

此時(shí),預(yù)覽以上代碼(  刪去這種注釋   ),會(huì)發(fā)現(xiàn)即使子元素進(jìn)行了浮動(dòng),父元素float container仍然會(huì)將其包圍,進(jìn)行高度自適應(yīng)。

相關(guān)文章

最新評(píng)論