如果一個網站是寬銀幕設計,當你左右拖動瀏覽器視窗時,網站寬度會隨視窗大小伸縮;而當視窗縮小到一定程度後,就會出現橫向捲軸,網站寬度不再繼續縮小。這個效果用 CSS 的 min-width 就能輕鬆實現,可惜數量龐大的 IE6 使用者並不支援這個便利屬性。別擔心,只要加上以下幾種寫法,就能完美解決。
height:auto!important;
height:580px;
min-height:580px;
把這三行程式碼加到需要最小高度的 div 即可。原理是利用 IE6 本身的 BUG——當區塊元素內部的內容超出該元素高度時,元素高度會被撐開,也就是說 IE6 中的 height 屬性本身就等同於 min-height。
min-height:200px;
_height:200px;
利用只有 IE6 能辨識的「_」前綴,讓 IE6 讀取 _height,其他瀏覽器則忽略。
#min-width{
min-width:900px;
_width:expression((document.documentElement.clientWidth||document.body.clientWidth)<900?"900px":"");
line-height:200px;
background:#ccc;
}
#mpage{
width:100%;
min-width:980px;
position:relative;
_width: expression(((document.compatMode && document.compatMode=='CSS1Compat')? document.documentElement.clientWidth : document.body.clientWidth) < 980? '980px' : 'auto');
}
以上四種方法,任何一種都能解決 IE6 不支援 min-width 的問題。其中方法四兼顧了標準模式與相容模式的判斷,相容性最好,本站採用的正是這種寫法。