css - 标题中不需要的空白

标签 css

预览:

Preview

如何从标题中删除这个空白?我没有玩标题的填充。

我有一个页眉和页 footer 分。此外,我还有一个部分用于整个内容,包括页眉、正文和页脚。是什么导致 header 中出现这个空白,我该如何删除它?

我的 CSS 代码:

*{
    font-family: sans-serif;
}
h2.header_headings{
    font-size: 45px;
    text-indent: 10px;
    line-height: 1px;
}
h3.header_headings{
    font-size: 20px;
    text-indent: 25px;
    line-height: 1px;
}
h1.body_headings{
    font-size: 27px;
}
h1.body_headings:first-letter{
    font-size: 200%;
}
img{
    float: left;
}
p{
    font-family: tahoma;
}
ul
{
    font-weight: bold;
    font-size: 18px;
}
a
{
    color: orange;
}
a:hover
{
    color: green;
}
li
{
    margin: 5px;
}
footer{
    font-size: 15px;
    text-align: center;
}
#copyright{
    vertical-align: middle;
}
#body{

    width: 800px;
    background-color: white;
    border-width: thick;
    border-color: black;
    border-style: solid;
    margin: auto;
    box-shadow: 0 0 30px #000000;
}
body{
    background-image: url("../images/bats.gif");
    background-repeat: repeat;
}
#header{
    border-bottom: 2px solid black;
    background: orange; /* For browsers that do not support gradients */
    background: -webkit-linear-gradient(45deg, white, orange 75%, black); /* For Safari 5.1 to 6.0 */
    background: -o-linear-gradient(45deg, white, orange 75%, black); /* For Opera 11.1 to 12.0 */
    background: -moz-linear-gradient(45deg, white, orange 75%, black); /* For Firefox 3.6 to 15 */
    background: linear-gradient(45deg, white, orange 75%, black); /* Standard syntax */
}
#footer{
    height: 50px;
    border-top: 2px solid black;
    background: orange; /* For browsers that do not support gradients */
    background: -webkit-linear-gradient(45deg, black, orange, white); /* For Safari 5.1 to 6.0 */
    background: -o-linear-gradient(45deg, black, orange, white); /* For Opera 11.1 to 12.0 */
    background: -moz-linear-gradient(45deg, black , orange, white); /* For Firefox 3.6 to 15 */
    background: linear-gradient(45deg, black, orange, white); /* Standard syntax */
}

我的 HTML5:

<!DOCTYPE html>
<html lang="en">
<section id="body">
    <section id="header">
        <head>
            <title>Halloween Store</title>
            <meta charset = "UTF-8">
            <link rel="stylesheet" type="text/css" href="styles/main.css"/>
            <link rel="stylesheet" type="text/css" href="styles/normalize.css"/>
            <img src="images/pumpkin.gif" alt="Pumpkin Picture">
            <h2 class="header_headings">The Halloween Store</h2>
            <h3 class="header_headings">For the little Goblin in all of us!</h3>
        </head>
    </section>
    <body>
        <h1 class="body_headings">Welcome to my site. Please come in and stay awhile.</h1>
        <p>I started this web site because Halloween has always been my favorite holiday.  But during the last year, I started selling some of my favorite Halloween products, and they've become quite a hit.</p>
        <p>If you click on the Personal link, you can browse my favorite Halloween pictures, stories, and films.  And if you join my email list, I will keep you up-to-date on all things Halloween.</p>

        <h2 class="body_headings">Product categories</h2>
        <ul>
            <li><a href="products/props.html">Props</a></li>
            <li><a href="products/Costumes.html">Costumes</a></li>
            <li><a href="products/Special Effects.html">Special Effects</a></li>
            <li><a href="products/Masks.html">Masks</a></li>
        </ul>
        <h2 class="body_headings">My guarantee</h2>
        <p>If you aren't completely satisfied with everything you buy from my site, you can return it for a full refund.  <b>No questions asked!</b></p>
    </body>
    <section id="footer">
        <footer>
            <p id="copyright">&copy; 2016 Ben Murach</p>
        </footer>
    </section>
</section>
</html>

最佳答案

那是因为 <h2> , 它有一个 margin-top20px .以下应该有效!

* {
  font-family: sans-serif;
}
h2.header_headings {
  font-size: 45px;
  text-indent: 10px;
  margin-top: 0;
}
h3.header_headings {
  font-size: 20px;
  text-indent: 25px;
}
h1.body_headings {
  font-size: 27px;
}
h1.body_headings:first-letter {
  font-size: 200%;
}
img {
  float: left;
}
p {
  font-family: tahoma;
}
ul {
  font-weight: bold;
  font-size: 18px;
}
a {
  color: orange;
}
a:hover {
  color: green;
}
li {
  margin: 5px;
}
footer {
  font-size: 15px;
  text-align: center;
}
#copyright {
  vertical-align: middle;
}
#body {
  width: 800px;
  background-color: white;
  border-width: thick;
  border-color: black;
  border-style: solid;
  margin: auto;
  box-shadow: 0 0 30px #000000;
}
body {
  background-image: url("../images/bats.gif");
  background-repeat: repeat;
}
#header {
  border-bottom: 2px solid black;
  background: orange;
  /* For browsers that do not support gradients */
  background: -webkit-linear-gradient(45deg, white, orange 75%, black);
  /* For Safari 5.1 to 6.0 */
  background: -o-linear-gradient(45deg, white, orange 75%, black);
  /* For Opera 11.1 to 12.0 */
  background: -moz-linear-gradient(45deg, white, orange 75%, black);
  /* For Firefox 3.6 to 15 */
  background: linear-gradient(45deg, white, orange 75%, black);
  /* Standard syntax */
}
#footer {
  height: 50px;
  border-top: 2px solid black;
  background: orange;
  /* For browsers that do not support gradients */
  background: -webkit-linear-gradient(45deg, black, orange, white);
  /* For Safari 5.1 to 6.0 */
  background: -o-linear-gradient(45deg, black, orange, white);
  /* For Opera 11.1 to 12.0 */
  background: -moz-linear-gradient(45deg, black, orange, white);
  /* For Firefox 3.6 to 15 */
  background: linear-gradient(45deg, black, orange, white);
  /* Standard syntax */
}
<!DOCTYPE html>
<html lang="en">
<section id="body">
  <section id="header">

    <head>
      <title>Halloween Store</title>
      <meta charset="UTF-8">
      <link rel="stylesheet" type="text/css" href="styles/main.css" />
      <link rel="stylesheet" type="text/css" href="styles/normalize.css" />
      <img src="images/pumpkin.gif" alt="Pumpkin Picture">
      <h2 class="header_headings">The Halloween Store</h2>
      <h3 class="header_headings">For the little Goblin in all of us!</h3>
    </head>
  </section>

  <body>
    <h1 class="body_headings">Welcome to my site. Please come in and stay awhile.</h1>
    <p>I started this web site because Halloween has always been my favorite holiday. But during the last year, I started selling some of my favorite Halloween products, and they've become quite a hit.</p>
    <p>If you click on the Personal link, you can browse my favorite Halloween pictures, stories, and films. And if you join my email list, I will keep you up-to-date on all things Halloween.</p>

    <h2 class="body_headings">Product categories</h2>
    <ul>
      <li><a href="products/props.html">Props</a>
      </li>
      <li><a href="products/Costumes.html">Costumes</a>
      </li>
      <li><a href="products/Special Effects.html">Special Effects</a>
      </li>
      <li><a href="products/Masks.html">Masks</a>
      </li>
    </ul>
    <h2 class="body_headings">My guarantee</h2>
    <p>If you aren't completely satisfied with everything you buy from my site, you can return it for a full refund. <b>No questions asked!</b>
    </p>
  </body>
  <section id="footer">
    <footer>
      <p id="copyright">&copy; 2016 Ben Murach</p>
    </footer>
  </section>
</section>

</html>

关于css - 标题中不需要的空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39888079/

相关文章:

javascript - 如何将元素 css 转换为 JSON?

javascript - 我怎样才能加入两个段落以内联显示而不移动对齐的文本?

html - django 静态文件在运行时不会更新

html - 如何解决背景图像在 CSS 中不显示的问题

html - 如何垂直对齐 :hover 上的文本

jquery - 使用模板渲染嵌套的 UL LI 并从代码中移除 TABLE

css - 用于对齐具有不同字体大小的多个 float 跨度的 "clean way"是什么?

javascript - 使用 Javascript 发布取消隐藏 div

jquery - 在 jQuery 中切换一个 p.class,但它一直在抓取标签之外的图像

html - 在 CSS 中围绕多个单词创建一个圆圈