2015-08-03 134 views
0

我有2个div与我的网页上的固定位置,我想滚动浏览器滚动条上下第二个div不是div滚动,有谁知道如何做到这一点?我希望这不是太混乱。使用浏览器滚动条滚动固定div内容

#firstDiv 
 
{ 
 
    position:fixed;width:70%;height:20%;background-color:red;  
 
} 
 
#secondDiv 
 
{ 
 
    top:20%;position:fixed;width:70%;background-color:blue;overflow-y:scroll;bottom:0px 
 
}
<html> 
 
<head> 
 
<title>somthing</title> 
 
</head> 
 
<body> 
 
<div> 
 
    <div id="firstDiv"> 
 
    </div> 
 
    <div id="secondDiv"> 
 
     <pre> 
 
\t \t some Text some Text some Text some Text some Text 
 
some Textsome Textsome Textsome Textsome Textsome Textsome 
 
some Textsome Textsome Textsome Textsome Textsome Textsome 
 

 

 
\t </pre> 
 
    </div> 
 
</div> 
 
</body> 
 
</html>

酒吧

回答

0

fixed特性使得两者的div上下滚动已经与用户。使用您当前的设置,您无法看到,因为您的网页上没有滚动或向下滚动。

你可能想要做的只是制作第一个格fixed,另一个格为static(标准值)。如果第二个div足够高,浏览器将添加一个滚动条,允许您在第一个div保持原位时向上/向下滚动第二个div。

看看这个片段(一定要单击“全页面”在右上角):

body { 
 
    margin:0; 
 
} 
 

 
#first { 
 
    position:fixed; 
 
    top:0; 
 
    width:100%; 
 
    height:100px; 
 
    background-color:red; 
 
} 
 
#second { 
 
    margin-top:100px; 
 
    width:100%; 
 
    height:1500px; 
 
    background-color:blue; 
 
}
<body> 
 
    <div id="first"> 
 
     First div 
 
    </div> 
 

 
    <div id="second"> 
 
     Some text more text even more text.<br /> 
 
     A new line here. More text.<br /> 
 
     Text text text text text text.<br /> 
 
     Text text text text text text.<br /> 
 
     Text text text text text text.<br /> 
 
     Text text text text text text.<br /> 
 
     Text text text text text text.<br /> 
 
     Text text text text text text.<br /> 
 
     Et cetera.<br /> 
 
    </div> 
 
</body>