Нежелательные пробелы в заголовке

#css

#css

Вопрос:

Предварительный просмотр:

Предварительный просмотр

Как я могу удалить это пустое пространство из заголовка? Я не играл с заполнениями заголовка.

У меня есть раздел для верхнего и нижнего колонтитулов. Кроме того, у меня есть раздел для всего этого, включая заголовок, тело, нижний колонтитул. Что вызывает это пустое пространство в заголовке и как я могу его удалить?

мой код 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">amp;copy; 2016 Ben Murach</p>
        </footer>
    </section>
</section>
</html>
  

Комментарии:

1. Можете ли вы также поделиться HTML-кодом?

2. @PraneshRavi Извините, я забыл добавить код HTML5. Я добавил его сейчас.

Ответ №1:

Это было из-за <h2> , у которого был margin-top of 20px . Следующее должно работать!

 * {
  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">amp;copy; 2016 Ben Murach</p>
    </footer>
  </section>
</section>

</html>