将背景图片移至顶部[CSS]

时间:2015-08-01 18:16:44

标签: html css background-image containers removing-whitespace

我的背景图片和页面顶部之间有空白区域,我正在尝试完成代码学院课程。 Picture of white-space above webpage content This应该是它的样子,这是我的代码:



html, body {
  margin: 0;
}

h1, h2, a {
  font-family: 'Oswald', sans-serif;
}


}

a:link {
  background:black;
  color:white;
  text-transform:uppercase;
}

a:hover {
  background:gold;
  color:white;
  text-transform:uppercase;
}

a:active {
  background:black;
  color:white;
  text-transform:uppercase;
}

a:visited {
  background:black;
  color:white;
  text-transform:uppercase;

}


p {
  font-family: Helvetica, Arial, sans-serif; 
}

.container {
  width: 940px;
  margin: 0 auto;
}

/* Main */
.main {
  background: url("https://s3.amazonaws.com/codecademy-content/projects/move/bg.jpg") no-repeat center center;
  background-size: cover;
  height: 600px;
}

.main .container {
  position:relative;
  top:100px;
}

.main {
  height: 600px;
}

.main h1 {
  font-size: 150px;
}

.main p {
  font-size: 18px;
}




/* Supporting */
.supporting {
  text-align: center;
  padding: 50px 0 80px;
}

.supporting .col {
  float: left;
  width: 28%;
  padding: 10px;
}

.supporting h1,
.supporting h2 {
  color: #ffa800;
  font-size: 20px;
  margin-bottom: 10px;
}

.clearfix {
  clear: both;
}

.supporting p {
  color: #efefef;
  margin-bottom: 20px;
  line-height: 20px;
  font-size: 12px;
}

.supporting .btn {
  background-color: #eee;
  color: #1c1c1c;
  font-size: 18px;
  padding: 8px 30px;
  text-decoration: none;
  display: inline-block;
}

/* Feature */
.feature {
  height: 600px;
}

.feature h1,
.feature h2 {
  color: #fff;
  font-size: 40px;
  margin: 0;
  padding:50px 0 0;
}

/* Footer */
.footer {
  height: 600px;
}

.footer h1,
.footer h2 {
  color: #fff;
  font-size: 40px;
  margin: 0 0 20px 0;
  padding:50px 0 0;
}

.footer p {
  color: #fff;
  margin: 0 0 20px 0;
  font-size: 18px;
}


@media (min-width:600px) {
  .main h1 {
    font-size: 200px;
  }

  .supporting .col {
    width: 30%;
  }

  .supporting h2 {
    font-size: 40px;
  }

  .supporting p {
    font-size: 14px;
  }

  .feature h2 {
    font-size: 60px;
  }
}

<head>
  <link href='https://fonts.googleapis.com/css?family=Oswald:400,700' rel='stylesheet' type='text/css'>
</head>
<body>
  <div class="main">
    <div class="container">
      <h1>Move</h1>
      <p>Form healthy habits fitness blah</p>
      <a href="#">Click Here</a>
    </div>
  </div>
  <div class="supporting">
    <div class="container">
      <div class="col">
        <h2>Move</h2>
        <p>Become more active by tracking your runs, rides, and walks.</p>
      </div>    
      <div class="clearfix"></div>
    </div>
  </div>
  <div class="feature">
    <div class="container">        
    </div>
  </div>   
</body>
&#13;
&#13;
&#13;

3 个答案:

答案 0 :(得分:3)

这是因为你有文字的边缘。 只需将margin:0;添加到h1, h2, a,如下所示即可解决您的问题。

h1, h2, a {
  margin:0;
  font-family: 'Oswald', sans-serif;
}

答案 1 :(得分:0)

.main .container {
    position:relative;
    top:100px; // Remove
}

html, body {
    margin: 0;
    padding: 0; // Add
}

答案 2 :(得分:-1)

尝试更改css文件中的以下内容

body {
 margin: -10px;
}

这会减少身体顶部的空白。这可能不是实际修复。