Top 0 的截邊問題 - daniel-qa/Vue GitHub Wiki
Top 0 的截邊問題
- top: 0 的意思
它會讓元素的「頂端」貼齊它的定位參考容器(scroll container)的頂端。
如果外層有 padding、margin 或 overflow 限制,元素就會「硬靠上去」,導致內容被擠掉或看起來被截斷。
- 解決方向
如果有 header,保留高度:
position: sticky;
top: 60px; /* header 的高度 */
position: sticky; top: 0; → 基準是「父容器的內邊界(padding-box)」,跟「上面的元件」無關,跟「本身 margin」也幾乎無關。