position: sticky 是一个混合体:元素的行为像 relative(保持在正常流中)直到它滚动到你指定的阈值,然后表现得像 fixed(固定在位置)——但仅当其containing block仍然在屏幕上时。
css
.section-header {
position: sticky;
top: 0; /* sticks when its top edge reaches the viewport top */
}
(或 //)值是 ——它定义阈值。没有它,sticky 什么都不做。
