有時候我們在制作網頁的時候,會遇到不同瀏覽器,對填充和邊距顯示的不同效果。導致心情納悶
現在提供解決這個困擾的方法!
對FF、Opear等支持Web標准的瀏覽器與比較頑固的IE瀏覽器進行針對性的CSS hack
/* FF、Opear等支持Web標准的瀏覽器 */
#header {
margin-top: 23px;
margin-bottom: 23px;
}
/* IE6瀏覽器 */
*html #header {
margin-top: 13px;
margin-bottom: 13px;
}
/* IE7瀏覽器 */
*+html #header {
margin-top: 18px;
margin-bottom: 18px;
}
因此,當你在遇到這種情況的時候可以用
* html 來定義IE6
*+html 來定義IE7
更新:
還有一種css hack直接與其他瀏覽器一起寫在一條css表達式中
#header{
margin-top: 13px; /* 所有瀏覽器都支持 */
margin-top: 13px !important; /* Firefox、IE7支持 */
_margin-top: 13px; /* IE6支持 */
*margin-top: 13px; /* IE6、IE7支持 */
+margin-top: 13px; /* IE7支持 */
margin-top: 13px\ 9; /* IE6、IE7、IE8、IE9支持 */
margin-top: 13px\ 0; /* IE8、IE9支持 */
}
需要注意書寫順序:所有瀏覽器、Firefox、IE8、IE7、IE6依次排列。
現在提供解決這個困擾的方法!
對FF、Opear等支持Web標准的瀏覽器與比較頑固的IE瀏覽器進行針對性的CSS hack
/* FF、Opear等支持Web標准的瀏覽器 */
#header {
margin-top: 23px;
margin-bottom: 23px;
}
/* IE6瀏覽器 */
*html #header {
margin-top: 13px;
margin-bottom: 13px;
}
/* IE7瀏覽器 */
*+html #header {
margin-top: 18px;
margin-bottom: 18px;
}
因此,當你在遇到這種情況的時候可以用
* html 來定義IE6
*+html 來定義IE7
更新:
還有一種css hack直接與其他瀏覽器一起寫在一條css表達式中
#header{
margin-top: 13px; /* 所有瀏覽器都支持 */
margin-top: 13px !important; /* Firefox、IE7支持 */
_margin-top: 13px; /* IE6支持 */
*margin-top: 13px; /* IE6、IE7支持 */
+margin-top: 13px; /* IE7支持 */
margin-top: 13px\ 9; /* IE6、IE7、IE8、IE9支持 */
margin-top: 13px\ 0; /* IE8、IE9支持 */
}
需要注意書寫順序:所有瀏覽器、Firefox、IE8、IE7、IE6依次排列。
