0
我有下面的代碼 - 我試圖讓「嘿!」只在白色容器內部固定。我嘗試在position:fixed
,z-index
中使用margin-left:0;margin-top:0
來將它從紅色和黑色容器中隱藏起來,但它不起作用。固定一個元素的位置只在div
<div style="height:1000px;background:red;">
</div>
<div style="height:400px;">
<div style="position:fixed;border:thin solid blue;top:0;left:0;">
hey!
</div>
</div>
<div style="height:1000px;background:black;">
</div>
我不明白你的問題。你想要歸檔什麼?你想讓「嘿」只在白色的東西里面滾動嗎? –
固定位置使得元素相對於整個文檔...而不是特定的容器。你要麼使用JavaScript來解決這個問題,要麼重新思考解決方案(取決於你想實現的目標) –