經典固定底部廣告條:position: fixed; bottom: 0; 現代瀏覽器完美支援。IE6 不支援 fixed,需用 _position: absolute + expression 模擬,並解決滾動抖動問題。
body {
background-image: url(text.txt); /* 觸發 IE6 背景重繪,消除抖動 */
background-attachment: fixed; /* 配合 fixed 定位 */
}
#bottomNav {
background-color: #096;
z-index: 999;
position: fixed;
bottom: 0; left: 0;
width: 100%;
_position: absolute; /* IE6 hack */
_top: expression(documentElement.scrollTop + documentElement.clientHeight - this.offsetHeight); /* IE6 模擬 fixed */
overflow: visible;
}
<div id="bottomNav">這裡加入你的代碼固定底部漂浮</div>
background-image: url(text.txt):檔案可不存在,目的是觸發 IE6 背景重繪機制,**消除 expression 滾動抖動**。_top: expression(...):即時計算滾動位置 + 視窗高度 - 自身高度,模擬 bottom:0。_position: absolute:IE6 只認 absolute,配合 expression 達到 fixed 效果。z-index: 999 確保廣告層級最高。#bottomNav { position: sticky; bottom: 0; z-index: 999; }
position: sticky 在現代瀏覽器(含 Edge、Chrome、Firefox、Safari)完美支援,無需 JS、無抖動、代碼極簡。IE 完全不支援,若必須支援 IE11 可保留 fixed 方案。