[英]position fixed element always inside the div
我需要能夠將固定元素始終定位在div中。 調整窗口大小時出現問題。 然后,固定div始終浮在所有其他元素之上。 如何預防呢? 我需要固定該div,但將其放置在div內。
這是一個例子:
<div id="main">
<div id="one" style="background-color:yellow;"></div>
<div id="two" style="background-color:black;"></div>
<div id="three" style="background-color:yellow;">
<div id="four"></div>
</div>
</div>
CSS:
#main
{
position:relative;
width:1200px;
top:0;
bottom:0;
left:100px;
}
#one,#two,#three
{
position:relative;
width:100px;
height:1000px;
float:left;
top:0;
bottom:0;
}
#four
{
position:fixed;
top:50px;
background-color:blue;
width:100px;
height:200px;
}
例如,嘗試左右移動水平滾動,您將看到發生了什么。
將位置更改為相對。
例
#four {
background-color: blue;
height: 200px;
position: relative;
top: 50px;
width: 100px;
}
查看關於類似問題的答案 。 不幸的是,您面臨的問題是僅靠CSS無法解決的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.