【发布时间】:2018-01-12 00:24:46
【问题描述】:
问题是,我在其他地方看到过这种方法。所以它应该工作。我不知道出了什么问题,因为浏览器开发工具显示该位置设置为粘性,但它没有粘住。
JSFiddle https://jsfiddle.net/Slava_B/qr9tpLmh/
.parent {
height: 1000px;
width: 200px;
position: relative;
display: inline-block;
}
.position-sticky {
position: -webkit-sticky;
position: sticky;
top: 0;
background: rgba(200, 220, 255, 0.5);
}
.position-first-child-sticky {
position: relative;
}
.position-first-child-sticky> :first-child {
position: -webkit-sticky;
position: sticky;
top: 0;
background: rgba(255, 220, 200, 0.5);
}
<div class="parent">
<div class="position-sticky">I'm sticky</div>
</div>
<div class="parent">
<div class="position-first-child-sticky">
<div>I'm fist-child-sticky</div>
</div>
</div>
【问题讨论】:
-
最新的 Firefox 和 Chrome...第二个“I'm first-child-sticky”是否也停留在您的浏览器中?
标签: css css-position sticky