正式說法:A sticky positioned box is offset relative to its nearest ancestor with a scrolling mechanism and its containing block;an inset such as top is required to establish the sticky threshold。
何時使用:章節導覽、表格標題或頁內工具列需要在局部捲動區停留時。
修改前後:Before:sticky 不動就一直加 z-index。After:先找 overflow ancestor、確認可捲動高度與 top threshold。
sticky 與祖先 overflow Sticky positioning and ancestor overflow
白話
sticky 會在自己的捲動容器裡黏住,不一定黏在整個瀏覽器視窗。
正式定義
A sticky positioned box is offset relative to its nearest ancestor with a scrolling mechanism and its containing block;an inset such as top is required to establish the sticky threshold。
正式說法:A stacking context is an atomic stacking unit created by defined triggers including positioned z-index, transform, or opacity below 1;descendant z-order is resolved within that context before the context participates in its parent。
A stacking context is an atomic stacking unit created by defined triggers including positioned z-index, transform, or opacity below 1;descendant z-order is resolved within that context before the context participates in its parent。