<div id="div1">
any not fixed text
but this div has scrollbar
<div id="div2">
this div is fixed (without scrollbar)
</div>
</div>
我需要div2
固定div1
,但不固定到主瀏覽器滾動條。像「將div2粘貼到div1」。
div1
有滾動條,這就是爲什麼我需要修復div2
。
如果我有這樣的:
#div1 {
position: absolute;
}
#div1 #div2 {
position: fixed;
}
就會好div1
和瀏覽器的窗口這兩個,但我只需要div1
。
實施例進行測試:
<html>
<head>
<style type="text/css">
#div1 {
border: 1px solid gray;
position: absolute;
height: 200px;
width: 400px;
overflow-y: scroll;
}
#div1 #div2 {
position: fixed;
margin-left: 300px;
}
</style>
</head>
<body>
<br><br><br>
<div id="div1">
<div id="div2">fixed text</div>
<div style="height: 400px;"></div>
</div>
<div style="height: 1400px;"></div>
</body>
</html>
Q1:如何修正div2
到div
Q2:在這種情況下如何float: right
div2
到的div1
右側(上例中爲〜margin-left: 350px;
)
謝謝。
附註:如果你有內部div的ID,那麼你應該在你的css中使用'#div2 {/ * style * /}'而不是'#div1#div2 {/ * style * /}'。 – Roimer