gpt4 book ai didi

html - 向下滚动时内容显示在固定 div 上方

转载 作者:太空宇宙 更新时间:2023-11-04 07:14:26 29 4
gpt4 key购买 nike

我认为这是一个简单的问题,但我无法理解它。我在页面顶部有一个固定的 div,当我向下滚动查看内容时,内容(文本)显示在该固定 div 上方 5 像素的边距中。该边距(黑色,请参阅 https://jsfiddle.net/xgtcnuL5/22/)用于正文中的背景图像。

我想保留最高边距,但我不想在那里看到内容。有什么想法吗?

* {
box-sizing: border-box;
}

body {
text-align: center;
background-color: #000;
font: 0.9em/1.2em arial, helvetica, verdana;
color: #4c4c4c;
}

#container {
margin: 0 auto;
position: relative;
max-width: 980px;
min-height: 700px;
background: #fff;
text-align: left;
color: #4c4c4c;
}

.header {
position: fixed;
overflow: hidden;
width: 90%;
max-width: 900px;
height: 165px;
background-color: #fff;
z-index: 10;
}

.top {
margin-left: 17%;
height: 165px;
}

.top img {
max-width: 396px;
margin-top: 55px;
}

.col1 {
float: left;
width: 17%;
text-align: left;
margin-top: 165px;
}

.nav {
position: fixed;
overflow: hidden;
font-weight: bold;
z-index: 11;
}

.col2 {
float: left;
width: 50%;
padding: 0 20px 20px 0;
margin-top: 165px;
}

.col3 {
float: left;
width: 33%;
padding: 0 15px 15px 5px;
text-align: left;
font-size: 90%;
margin-top: 165px;
}
<div id="container">
<div class="header">
<div class="top">
<a href="#home"><img src="img/logo2.jpg" alt="logo" width="100%" /></a>
</div>
</div>
<div style="overflow:auto">
<div class="col1">
<div class="nav">
</div>
</div>
<div class="col2">content
</div>
<div class="col3">content
</div>
</div>
</div>

最佳答案

* {
box-sizing: border-box;
}

body {
text-align: center;
background: #000 url('../img/bg.jpg') repeat top right;
font: 0.9em/1.2em arial, helvetica, verdana;
color: #4c4c4c;
}

#container {
margin: 0 auto;
position: relative;
max-width: 980px;
min-height: 700px;
background: #fff;
text-align: left;
color: #4c4c4c;
}

.header {
position: fixed;
overflow: hidden;
width: 90%;
max-width: 980px;
height: 165px;
background-color: #fff;
z-index: 10;
}

.top {
margin-left: 17%;
height: 165px;
}

.top img {
max-width: 396px;
margin-top: 55px;
}

.col1 {
float: left;
width: 17%;
text-align: left;
margin-top: 165px;
}

.nav {
position: fixed;
overflow: hidden;
font-weight: bold;
z-index: 11;
}


.col2 {
float: left;
width: 50%;
padding: 0 20px 20px 0;
margin-top: 165px;
}

.col3 {
float: left;
width: 33%;
padding: 0 15px 15px 5px;
text-align: left;
font-size: 90%;
margin-top: 165px;
}

body {
margin: 0;
}
<div id="container">
<div class="header">
<div class="top">
<a href="#home"><img src="img/logo2.jpg" alt="logo" width="100%" /></a>
</div>
</div>
<div style="overflow:auto">
<div class="col1">
<div class="nav">
</div>
</div>
<div class="col2">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis,
sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus.
Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet.
Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui.
</div>
<div class="col3">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis,
sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus.
Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet.
Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui.
</div>
</div>
</div>

希望下面的代码对你有所帮助

body {
margin: 0;
}

谢谢

关于html - 向下滚动时内容显示在固定 div 上方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50855552/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com