【发布时间】:2021-04-18 18:34:39
【问题描述】:
我想在可滚动的 div 和绝对位置子按钮中直接放置按钮,但不在可滚动的 div 内。
当我滚动包含按钮的 div 时,我希望按钮下方的内容(蓝色方块)也随着 div 滚动,因此蓝色方块始终位于按钮的正下方。就像现在一样,蓝色方块总是停留在同一个地方。但是,当我将父位置设为相对位置时,蓝色方块在可滚动 div 内(带有黑色边框的那个),我想要它在外面。
<div style="width: 500px; height: 50px; border: 2px solid black; overflow-x: auto; overflow-y: hidden; white-space: nowrap;">
<div style="display: inline-block; width: 250px;">
<button style="width: 100%; height: 100%;">Hello</button>
<div style="position: absolute; background-color: blue; width: 50px; height: 50px;"></div>
</div>
<div style="display: inline-block; width: 250px;">
<button style="width: 100%; height: 100%;">Hello</button>
<div style="position: absolute; background-color: blue; width: 50px; height: 50px;"></div>
</div>
<div style="display: inline-block; width: 250px;">
<button style="width: 100%; height: 100%;">Hello</button>
<div style="position: absolute; background-color: blue; width: 50px; height: 50px;"></div>
</div>
<div style="display: inline-block; width: 250px;">
<button style="width: 100%; height: 100%;">Hello</button>
<div style="position: absolute; background-color: blue; width: 50px; height: 50px;"></div>
</div>
</div>
有没有人知道如何进行这项工作?我正在查看stackoverflow,但没有帮助,我认为我对定位非常了解,但可能还不够好。如果您知道如何修复定位或以完全不同的方式进行定位,我将不胜感激:)
【问题讨论】:
-
容器
height: 50px;是否有意在黑框外显示框?
标签: html css scroll css-position