我卡在这个问题上一段时间,想和大家分享一下 position: sticky
+ flexbox 的一个坑:
我的粘性div在被嵌套在flexbox容器中之前是工作正常的,但当它被包裹在一个flexbox父容器中时,突然间就不再粘了。
.flexbox-wrapper {
display: flex;
height: 600px;
}
.regular {
background-color: blue;
}
.sticky {
position: -webkit-sticky;
position: sticky;
top: 0;
background-color: red;
}
<div class="flexbox-wrapper">
<div class="regular">
This is the regular box
</div>
<div class="sticky">
This is the sticky box
</div>
</div>