CSS 定位中,absolute 與 fixed 很容易混淆。前者通常相對於已定位的父元素,後者則相對於視窗。
absolute
fixed
.parent { position: relative; } .child { position: absolute; left: 10px; top: 20px; }
若沒有為父元素設定定位,absolute 可能會往外找到更上層的參考對象。fixed 則不受父元素影響,但舊版 IE 支援度較差。