我有
<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;)
谢谢你。