css+div 總結

所有瀏覽器的通用:height:100px;

IE6:_height:100px;/*height:100px;

IE7:*+height:100px;

IE6,IE7:*height:100px;

IE7,FF:height:100px !important;

注意:*+html 對IE7的兼容 必須保證HTML頂部有如下聲明:

代碼:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

1, !important (不是很推薦,用下面的一種感覺最安全)
隨着IE7對!important的支持, !important 方法現在只針對IE6的兼容.(注意寫法.記得該聲明位置需要提前.)
代碼:
<style>
#wrapper {
width: 100px!important; /* IE7+FF */
width: 80px; /* IE6 */
}
</style>

2, IE6/IE77對FireFox <from 針對firefox ie6 ie7的css樣式>
*+html 與 *html 是IE特有的標籤, firefox 暫不支持.而*+html 又爲 IE7特有標籤.
代碼:
<style>
#wrapper { width: 120px; } /* FireFox */
*html #wrapper { width: 80px;} /* ie6 fixed */
*+html #wrapper { width: 60px;} /* ie7 fixed, 注意順序 */
</style>

三、其他兼容技巧(相當有用)

1, FF下給 div 設置 padding 後會導致 width 和 height 增加, 但IE不會.(可用!important解決)
2, 居中問題.
1).垂直居中.將 line-height 設置爲 當前 div 相同的高度, 再通過 vetical-align: middle.( 注意內容不要換行.)
2).水平居中. margin: 0 auto;(當然不是萬能)
3, 若需給 a 標籤內內容加上 樣式, 需要設置 display: block;(常見於導航標籤)
4, FF 和 IE 對 BOX 理解的差異導致相差 2px 的還有設爲 float的div在ie下 margin加倍等問題.
5, ul 標籤在 FF 下面默認有 list-style 和 padding . 最好事先聲明, 以避免不必要的麻煩. (常見於導航標籤和內容列表)
6, 作爲外部 wrapper 的 div 不要定死高度, 最好還加上 overflow: hidden.以達到高度自適應.
7, 關於手形光標. cursor: pointer. 而hand 只適用於 IE.貼上代碼:

兼容代碼:兼容最推薦的模式。
/* FF */
.submitbutton {
float:left;
width: 40px;
height: 57px;
margin-top: 24px;
margin-right: 12px;
}
/* IE6 */
*html .submitbutton {
margin-top: 21px;
}
/* IE7 */
*+html .submitbutton {
margin-top: 21px;


3 盒模型不同解釋.

#box{
width:600px;
//for ie6.0- w\idth:500px;
//for ff+ie6.0
}
#box{
width:600px!important
//for ff
width:600px;
//for ff+ie6.0
width /**/:500px;
//for ie6.0-
}

浮動ie產生的雙倍距離
#box{ float:left; width:100px; margin:0 0 0 100px; //這種情況之下IE會產生200px的距離 display:inline; //使浮動忽略}
這裏細說一下block,inline兩個元素,Block元素的特點是:總是在新行上開始,高度,寬度,行高,邊距都可以控制(塊元素);Inline元素的特點是:和其他元素在同一行上,…不可控制(內嵌元素);
#box{ display:block; //可以爲內嵌元素模擬爲塊元素 display:inline; //實現同一行排列的的效果 diplay:table;


 清除浮動
.兼容box{
display:table;
//將對象作爲塊元素級的表格顯示
}
或者
.兼容box{
clear:both;
}

或者加入:after(僞對象),設置在對象後發生的內容,通常和content配合使用,IE不支持此僞對象,非Ie 瀏覽器支持,所以並不影響到IE/WIN瀏覽器。這種的最麻煩的
……#box:after{
content: “.”;
display: block;
height: 0;
clear: both;
visibility: hidden;
}


屏蔽IE瀏覽器(也就是IE下不顯示)
*:lang(zh) select {font:12px !important;} /*FF,OP可見*/
select:empty {font:12px !important;} /*safari可見*/
這裏select是選擇符,根據情況更換。第二句是MAC上safari瀏覽器獨有的。

僅IE7識別
*+html {…}
當面臨需要只針對IE7做樣式的時候就可以採用這個兼容。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章