html - 将背景图片移到顶部 [CSS]

标签 html css background-image containers removing-whitespace

我的背景图片和页面顶部之间有空白,我正在尝试完成代码学院类(class)。 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>

最佳答案

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

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

关于html - 将背景图片移到顶部 [CSS],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31764770/

相关文章:

asp.net - 在 PDF iText ASP C# 中为我的所有页面设置修复背景图像

asp.net - 如何将 CssClass 应用于一系列具有不同 ID 的相似对象

HTML 页脚被滚动条隐藏

html - 使子菜单比主菜单宽

html - 特定于 Mozilla 的 CSS

html - 如何在 SVG 标签上循环 CSS 动画

css - 如何将resizeMode设置为 "contain"的ImageBackground放在顶部?

css - 为什么 CSS background-image url 不显示我的图像,尽管链接和路径是正确的?

javascript - 使用 val() 获取空值

javascript - 使用 Javascript 将链接引用包装为 Ajax 调用