【发布时间】:2011-07-09 18:00:59
【问题描述】:
我发现当我定位一个元素时,无论父元素是否相对定位,它都会相对于窗口定位固定?
#wrapper {
width: 300px;
background: orange;
margin: 0 auto;
position: relative;
}
#feedback {
position: fixed;
right: 0;
top: 120px;
}
<div id="wrapper">
...
<a id="feedback" href="#">Feedback</a>
</div>
【问题讨论】:
-
"position:sticky" 将是解决方案。截至 2016 年 4 月,Firefox 似乎是唯一支持此功能的浏览器 (caniuse.com/#feat=css-sticky)。
-
在最近的浏览器中(在提出这个问题后发布),有更好的解决方案。请参阅标记为2016 update 的答案