标题和静态图像之间的Html间隙

时间:2017-06-12 01:24:54

标签: html css

我一直在尝试在我的网站上使用静态图像,但是标题和图像之间存在很大差距,我尝试删除填充并在Photoshop和HTML中更改图像高度。 这是我的问题https://jsfiddle.net/o27w80ve/

的小提琴



section.module:last-child {
  margin-bottom: 0;
}

section.module h2 {
  font-family: "Roboto Slab", serif;
  font-size: 30px;
}

section.module p {
  margin-bottom: 40px;
  font-size: 16px;
  font-weight: 300;
}

section.module p:last-child {
  margin-bottom: 0;
}

section.module.content {
  padding: 40px 0;
  color: #090C02;
}

section.module.content#section1 {
  background-color: #b23783;
}

section.module.content#section2 {
  background-color: #3783b2;
}

section.module.parallax {
  height: 600px;
  background-position: 50% 50%;
  background-repeat: no-repeat;
  background-attachment: fixed;
  background-size: cover;
}

section.module.parallax h1 {
  color: #8FD5A6;
  font-size: 48px;
  line-height: 600px;
  font-weight: 700;
  text-align: center;
  text-transform: uppercase;
  text-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
  font-family: 'Julius Sans One', sans-serif;
}

section.module.parallax-1 {
  background-image: url("https://i.imgur.com/YpRAOt3.jpg");
}

@media all and (min-width: 600px) {
  section.module h2 {
    font-size: 42px;
  }
  section.module p {
    font-size: 20px;
  }
  section.module.parallax h1 {
    font-size: 96px;
  }
}

@media all and (min-width: 960px) {
  section.module.parallax h1 {
    font-size: 160px;
  }
}

.header ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background-color: #1e1e20;
}

.header li {
  float: right;
  text-align: middle;
}

.header li a {
  display: block;
  color: white;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
  font-family: 'Bitter', serif;
}

.header li:hover {
  background-color: #fec10e;
  color: black;
}

<header class="header">
  <div>
    <ul>
      <li><a href="/">Testr Co.</a></li>
      <li><a href="#">Home</a></li>
      <li><a href="#">About Us</a></li>
      <li><a href="#">Blog</a></li>
    </ul>
  </div>
</header>
<section class="module parallax parallax-1">
  <div class="container">
    <h1>Example</h1>
  </div>
</section>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:1)

这被称为“保证金崩溃”。 margin-top上的defaut h1正在父级之外折叠。

https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Box_Model/Mastering_margin_collapsing

  

父级和第一个/最后一个孩子 - 如果没有边框,填充,内联内容,block_formatting_context创建或清除以将块的边距顶部与其第一个子节点的边距顶部分开阻止或没有边框,填充,内联内容,高度,最小高度或最大高度将块的边距底部与其最后一个子节点的边距底部分开,然后这些边距会崩溃。折叠的保证金最终在父母之外。

section.module:last-child {
  margin-bottom: 0;
}

section.module h2 {
  font-family: "Roboto Slab", serif;
  font-size: 30px;
}

section.module p {
  margin-bottom: 40px;
  font-size: 16px;
  font-weight: 300;
}

section.module p:last-child {
  margin-bottom: 0;
}

section.module.content {
  padding: 40px 0;
  color: #090C02;
}

section.module.content#section1 {
  background-color: #b23783;
}

section.module.content#section2 {
  background-color: #3783b2;
}

section.module.parallax {
  height: 600px;
  background-position: 50% 50%;
  background-repeat: no-repeat;
  background-attachment: fixed;
  background-size: cover;
}

section.module.parallax h1 {
  color: #8FD5A6;
  font-size: 48px;
  line-height: 600px;
  font-weight: 700;
  text-align: center;
  text-transform: uppercase;
  text-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
  font-family: 'Julius Sans One', sans-serif;
  margin-top: 0;
}

section.module.parallax-1 {
  background-image: url("https://i.imgur.com/YpRAOt3.jpg");
}

@media all and (min-width: 600px) {
  section.module h2 {
    font-size: 42px;
  }
  section.module p {
    font-size: 20px;
  }
  section.module.parallax h1 {
    font-size: 96px;
  }
}

@media all and (min-width: 960px) {
  section.module.parallax h1 {
    font-size: 160px;
  }
}

.header ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background-color: #1e1e20;
}

.header li {
  float: right;
  text-align: middle;
}

.header li a {
  display: block;
  color: white;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
  font-family: 'Bitter', serif;
}

.header li:hover {
  background-color: #fec10e;
  color: black;
}
<header class="header">
  <div>

    <ul>
      <li><a href="/">Testr Co.</a></li>
      <li><a href="#">Home</a></li>
      <li><a href="#">About Us</a></li>
      <li><a href="#">Blog</a></li>
    </ul>
  </div>
</header>
<section class="module parallax parallax-1">
  <div class="container">
    <h1>Example</h1>
  </div>
</section>

答案 1 :(得分:0)

检查完代码后,您会注意到'section.module.parallax h1'的边距为40px。 你需要使用它(margin-top:0)来消除差距。

相关问题