IE6 的某些元素在呈現上會多出一點空白間隙,更形象地說,就是多了一段「外邊距(margin)」——要嘛是 margin-top、要嘛是 margin-bottom,當然也可能是 margin-left、margin-right。這在表單元素中特別常見,哪怕我們的 reset CSS 已經把這些元素的 margin 設為 0。
看個實例:假如我們想模擬一個雙邊框的文字框,如下圖:

HTML 代碼:
1.<span><input type="text" name="textfield2" id="textfield2" /></span>
CSS 代碼:
1.span{border:1px solid #FCCC83; display:inline-block; overflow:hidden; zoom:1}
2..url-input{ width:200px; height:18px; background-color:#FFFFFF; padding:2px 0 0 3px; border:1px solid #FA9806;}
在其他瀏覽器下都正常,唯獨 IE6(IE7 未測試)呈現如下:

span 與 input 之間明顯隔著一段間距,實在令人無言。即使我們把 input 設為 margin:0; padding:0; 也沒用。百般無奈之下,只好讓 input 浮動——因為過去也碰過類似問題(【IE6 的瘋狂之六】li 在 IE 中底部 3 像素的 BUG,正是靠增加浮動來解決)。
HTML 代碼:
1.<div>輸入視頻、網頁、音樂的地址: <span><input type="text" name="textfield2" id="textfield2" /></span> <input type="submit" name="button" value="分享" /> </div>
CSS 代碼:
1.*{ margin:0; padding:0; font-size:12px}
2..share-submit{margin:5px 0 20px; background-color:#F9FBFC; border:1px solid #D1D6E2; padding:8px; overflow:hidden; zoom:1; width:550px; margin:20px auto }
3..share-submit .url-input{width:200px;height:18px;background-color:#FFFFFF; padding:2px 0 0 3px; float:left;border:1px solid #FA9806}
4..share-submit span,.share-submit input{ vertical-align:middle}
5..share-submit span{border:1px solid #FCCC83; display:inline-block; overflow:hidden; zoom:1}
這個問題我昨天也拿到 CSS 森林討論過,期待能找到更好的解法,一開始卻一無所獲。經過多次測試,發現這個「浮動」的方法屢試不爽——雖然還不清楚背後的真正原因,但好歹是個可行的方案。歡迎留言分享你的解法,也歡迎拍磚!如果你知道成因,更懇請留言告知,感激不盡!