修复一个position固定元素不管父元素有没有滚动条右边位置都一样

Fix a position fixed element's right position to be the same regardless or whether or not the parent has a scrollbar

如何强制 position: fixed; 元素始终与 right 正好相距 16px,而不管其父元素的内容是否溢出?

<div style="overflow: auto; position: absolute; right: 0;">
 <div style="position: fixed; right: 0;">
  <div><span>Hide Something</span></div>
  <div><span>Show Something</span></div>
 </div>
</div>

显然,将 position: absolute; 添加到第三个元素会强制定位(例如 right: 16px;right: 0;),而不管(现在的 grand)父元素是否溢出。

<div style="overflow: auto; position: absolute; right: 0;">
 <div style="position: fixed; right: 0;">
  <div style="position: absolute; right: 16px;"><span>Hide Something</span></div>
  <div><span>Show Something</span></div>
 </div>
</div>

不确定我是否完全理解这一点,但看起来您应该能够将 right: 16px 设置为 position: fixed 元素。