滚动时有人可以帮我让div消失吗?
例如,如果我有一个简单的标题和下面的一堆段落,我滚动,我希望标题保持固定在顶部,它下面的段落滚动过去并消失在标题下方。到目前为止,我尝试了以下内容:
https://jsfiddle.net/5k8u9w9t/2/
基本上,我将标题的样式设置为position: fixed
,但段落不会消失。有人可以帮忙吗?
提前致谢!
答案 0 :(得分:2)
这会整理一下......
.container1 {
position: fixed;
top: 0;
width: 100vw;
background-color: #FFFFFF;
z-index: 1;
}
.container2 {
position: relative;
margin-top: 80px;
}
答案 1 :(得分:0)
我不确切地知道你想要做什么,但也许这可以回答你的问题:
.container1 {
position: fixed;
z-index: 1;
background: #fff;
}
答案 2 :(得分:0)
这是你在找什么?
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {margin:0;}
.navbar {
overflow: hidden;
background-color: #333;
position: fixed;
top: 0;
width: 100%;
}
.navbar a {
float: left;
display: block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
.navbar a:hover {
background: #ddd;
color: black;
}
.main {
padding: 16px;
margin-top: 30px;
height: 1500px; /* Used in this example to enable scrolling */
}
</style>
</head>
<body>
<div class="navbar">
<a href="#home">Home</a>
<a href="#news">News</a>
<a href="#contact">Contact</a>
</div>
<div class="main">
<h1>Fixed Top Menu</h1>
<h2>Scroll this page to see the effect</h2>
<h2>The navigation bar will stay at the top of the page while scrolling</h2>
<p>Some text some text some text some text..</p>
<p>Some text some text some text some text..</p>
<p>Some text some text some text some text..</p>
<p>Some text some text some text some text..</p>
<p>Some text some text some text some text..</p>
<p>Some text some text some text some text..</p>
<p>Some text some text some text some text..</p>
<p>Some text some text some text some text..</p>
<p>Some text some text some text some text..</p>
<p>Some text some text some text some text..</p>
<p>Some text some text some text some text..</p>
<p>Some text some text some text some text..</p>
<p>Some text some text some text some text..</p>
<p>Some text some text some text some text..</p>
<p>Some text some text some text some text..</p>
<p>Some text some text some text some text..</p>
<p>Some text some text some text some text..</p>
<p>Some text some text some text some text..</p>
<p>Some text some text some text some text..</p>
<p>Some text some text some text some text..</p>
</div>
</body>
</html>