向下滚动时,内容显示在固定div之上

时间:2018-06-14 10:41:01

标签: html css

我认为这是一个简单的问题,但我无法理解它。 我在页面顶部有一个固定的div,当我向下滚动查看内容时,内容(文本)显示在5px边距内的固定div上方。 该边距(黑色,见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>

2 个答案:

答案 0 :(得分:1)

* {
  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;
}

由于

答案 1 :(得分:0)

margin:0; CSS

中添加body

* {
  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;
  margin: 0;
}

#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;
}
<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>