所有瀏覽器 通用
height: 100px;
IE6 專用
_height: 100px;
IE6 專用
*height: 100px;
IE7 專用
*+height: 100px;
IE7、FF 共用
height: 100px !important;
一、CSS 兼容
以下兩種方法幾乎能解決現(xiàn)今所有兼容.
1, !important (不是很推薦,用下面的一種感覺最安全)
隨著IE7對!important的支持, !important 方法現(xiàn)在只針對IE6的兼容.(注意寫法.記得該聲明位置需要提前.)
代碼:
<style>
#wrapper {
width: 100px!important; /* IE7+FF */
width: 80px; /* IE6 */
}
</style>
2, IE6/IE77對FireFox <from 針對firefox ie6 ie7的css樣式>
*+html 與 *html 是IE特有的標(biāo)簽, firefox 暫不支持.而*+html 又為 IE7特有標(biāo)簽.
代碼:
<style>
#wrapper { width: 120px; } /* FireFox */
*html #wrapper { width: 80px;} /* ie6 fixed */
*+html #wrapper { width: 60px;} /* ie7 fixed, 注意順序 */
</style>
注意:
*+html 對IE7的兼容 必須保證HTML頂部有如下聲明:
代碼:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
二、萬能 float 閉合(非常重要!) 可以用這個解決多個div對齊時的間距不對,
關(guān)于 clear float 的原理可參見 [How To Clear Floats Without Structural Markup]將以下代碼加入Global CSS 中,給需要閉合的div加上 class=”clearfix” 即可,屢試不爽.
代碼:
<style>
/* Clear Fix */
.clearfix:after {
content:".";
display:block;
height:0;
clear:both;
visibility:hidden;
}
.clearfix {
display:inline-block;
}
/* Hide from IE Mac /*/
.clearfix {display:block;}
/* End hide from IE Mac */
/* end of clearfix */
</style>
***********************************************************************************************************************
三、其他兼容技巧(相當(dāng)有用)
1, FF下給 div 設(shè)置 padding 后會導(dǎo)致 width 和 height 增加, 但I(xiàn)E不會.(可用!important解決)
2, 居中問題.
1).垂直居中.將 line-height 設(shè)置為 當(dāng)前 div 相同的高度, 再通過 vetical-align: middle.( 注意內(nèi)容不要換行.)
2).水平居中. margin: 0 auto;(當(dāng)然不是萬能)
3, 若需給 a 標(biāo)簽內(nèi)內(nèi)容加上 樣式, 需要設(shè)置 display: block;(常見于導(dǎo)航標(biāo)簽)
4, FF 和 IE 對 BOX 理解的差異導(dǎo)致相差 2px 的還有設(shè)為 float的div在ie下 margin加倍等問題.
5, ul 標(biāo)簽在 FF 下面默認(rèn)有 list-style 和 padding . 最好事先聲明, 以避免不必要的麻煩. (常見于導(dǎo)航標(biāo)簽和內(nèi)容列表)
6, 作為外部 wrapper 的 div 不要定死高度, 最好還加上 overflow: hidden.以達(dá)到高度自適應(yīng).
7, 關(guān)于手形光標(biāo). cursor: pointer. 而hand 只適用于 IE.貼上代碼:
兼容代碼:兼容最推薦的模式。
新聞熱點(diǎn)
疑難解答
圖片精選