滚动框不起作用/滚动时使相对定位的元素消失在固定元素下



我是网页设计的初学者,在制作滚动框时遇到了困难。我正在尝试让一个相对位置元素能够用固定的标题(导航栏)滚动,并且相对元素在向上滚动后可以放在下面或"消失"。

<html>
<style> 
.toplinks{
position:fixed;
list-style-type: none;
margin-top:70px;
margin-left:300px;
padding:0;
font-size: 18px;
overflow: hidden;
background-color: white;
display: block;
color: black;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
#paragraph{
font-size: 15px;
position:relative;
overflow:auto;
width:65%;
height:30%;
top:250px;
left:250px;
z-index:-3;
}
</style>
<body>
<div class="toplinks">
<ui> <li> link</li>
<li><link</li>
<li>link</li>
<li>link</li></div>
<div id="paragraph"> heres a block of text that will probably also
have a picture that I want to be able to be scrollable with 
the navigation bar up top fixed </div> 
</body>
</html>

@Jamie Theophilos

首先,您的代码有很多问题,比如您没有关闭ul标记,也使用了<li标签下

只需执行其余操作,CSSHtml就可以了。您也可以检查此URL,该URL与您自己的代码配合良好:https://jsfiddle.net/itskamalkumar/zr9aLcz9/

Html

<div class="toplinks">
<ul>
<li>link</li>
<li>link</li>
<li>link</li>
<li>link</li>
</ul>
</div>
<div id="paragraph"> heres a block of text that will probably also
have a picture that I want to be able to be scrollable with 
the navigation bar up top fixed heres a block of text that will probably also
have a picture that I want to be able to be scrollable with 
the navigation bar up top fixed heres a block of text that will probably also
have a picture that I want to be able to be scrollable with 
the navigation bar up top fixed heres a block of text that will probably also
have a picture that I want to be able to be scrollable with 
the navigation bar up top fixed heres a block of text that will probably also
have a picture that I want to be able to be scrollable with 
the navigation bar up top fixed also
have a picture that I want to be able to be scrollable with 
the navigation bar up top fixed heres a block of text that will probably also
have a picture that I want to be able to be scrollable with 
the navigation bar up top fixed also
have a picture that I want to be able to be scrollable with 
the navigation bar up top fixed heres a block of text that will probably also
have a picture that I want to be able to be scrollable with 
the navigation bar up top fixed also
have a picture that I want to be able to be scrollable with 
the navigation bar up top fixed heres a block of text that will probably also
have a picture that I want to be able to be scrollable with 
the navigation bar up top fixed</div>

CSS

.toplinks{
position:fixed;
list-style-type: none;
margin-top:70px;
margin-left:150px;
padding:0;
font-size: 18px;
overflow: hidden;
background-color: white;
display: block;
color: black;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
#paragraph{
font-size: 15px;
position:relative;
overflow:auto;
width:65%;
height:30%;
top:250px;
left:150px;
z-index:-3;
}

最新更新