IE6 又一經典離譜 Bug:當父容器寬度或高度為奇數像素,且子元素 position: absolute; right: 0 或 bottom: 0 時,子元素會向右/下偏移 1px。根因:IE6 內部像素取整算法缺陷(除以 2 向下取整)。
<div id="out">
<div id="inn">內部絕對定位 DIV</div>
</div>
#out {
width: 609px; /* 奇數寬度 → Bug 觸發 */
height: 300px;
position: relative;
background: #FF0000;
color: #FFF;
}
#inn {
width: 200px;
height: 250px;
position: absolute;
top: 0; right: 0; /* 預期貼右對齊 */
background: #000;
}

right: 0 位置時,基於父容器 offsetWidthleft = parent.offsetWidth - child.offsetWidthoffsetWidth 為奇數時,IE6 內部除以 2 計算中心點時向下取整,導致 0.5px 誤差累積為 1px 偏移height 奇數 + bottom: 0 會導致下偏移 1px#out { width: 610px; /* 或 608px */ }
適用於固定寬度佈局,響應式佈局中可用 width: 100%; max-width: 610px; 避免奇數。
#inn {
left: 50%; margin-left: -100px; /* 寬度一半 */
/* 避開 right 計算 */
}
#out { padding-right: 1px; } /* 或 box-sizing: border-box 配合 width: 610px */
#inn { right: 0; _right: -1px; } /* 下劃線 Hack 只被 IE6 識別 */
直接忽略 IE6。 微軟 2014 年停止支持,全球份額 < 0.1%,中國政府/企業內網極少數除外。若必須維護:
ie6.css 修復Modernizr 檢測加載 PolyfillIE6 Bug 百科還有:雙倍邊距、3px 間隙、Peekaboo、Guillotine、hasLayout 觸發、PNG 透明、z-index 錯亂、表單元素層級最高、hover 僅支持 a... 歷史見證了 Web 發展的痛苦與進步,現代瀏覽器引擎(Blink/WebKit/Gecko)已徹底修正這些邏輯缺陷。