滚动 div#container 时,如果 div.item 在视野内,如果保证 String-String 一直在视野内?
div#container
div.item
String-String
https://codepen.io/homor/pen/BaLPoQb
代码如下:
<div id="container"> <div class="stage"> <div class="item"> String-String </div> </div> </div> <style> #container{ width: 300px; height: 80px; overflow: scroll; } .stage{ width: 1000px; position: relative; } .item{ position: absolute; left: 100px; right: 200px; width: 400px; text-align: center; background-color: yellow; } </style>
有没有优雅的办法可以实现?
<span>String-String</span>span {
position: sticky; left: 0;
}
用sticky定位,不知道是不是楼主想要的
2.1m questions
2.1m answers
60 comments
57.0k users