增加字体大小会大大增加标题的填充

时间:2015-10-13 22:28:45

标签: html css fonts

我创建了一个页面,当我注意到当我增加或减少标题的字体大小时,周围的空间会以极大的大小增加。我没有为h1标签填充,但看起来它正在被添加。我尝试删除导航的填充,但它只影响导航文本本身,而不是影响我的额外空间。 这是代码:



body {
  margin: 0;
  font-family: Caviar, "Times New Roman", sans-serif;
  float: clear;
  text-align: center;
}
#main {
  width: 100%;
  padding: 0;
}
/* start the whole heading section */

h1 {
  font-size: 5em;
  color: #000000;
  font-family: "Alex Brush", "Times New Roman", sans-serif;
  padding-left: 2%;
  float: left;
}
nav h2 {
  font-weight: normal;
}
nav {
  float: right;
  font-family: Junction, "Times New Roman", sans-serif;
  font-size: 1.1em;
  /*padding-top: 5.2%;
padding-right: 2%;*/
}
nav a {
  color: #000000;
  text-decoration: none;
}
nav a:hover {
  text-decoration: underline;
}
nav a:visited {
  color: #000b26;
}
#header {
  background-color: #FF6978;
  display: block;
  width: 100%;
  text-align: left;
  position: fixed;
  overflow: hidden;
  top: 0;
  z-index: 999;
  box-shadow: 5px 6px 5px #000000;
}
/*end heading section*/

#container {
  margin: 0 auto 0 auto;
  margin-left: 0 auto;
  width: 96%;
  margin-top: 13%;
}
.small_head {
  font-family: Capsuula, "Times New Roman", sans-serif;
  font-size: 2.2em;
  border: 3px solid #FFFF61;
  padding: .5% 5% .5% 5%;
  display: inline-block;
  margin: 0 auto;
}

<!doctype html>
<html lang="en">

<head>
  <title>Check</title>
  <meta charset="UTF-8">
  <link href="styles.css" rel="stylesheet" type="text/css">
  <link href="font.css" rel="stylesheet" type="text/css">
</head>

<body>
  <div id="main">
    <!--open main div-->

    <div id="header">
      <h1>Checking Head</h1>
      <nav>
        <h2>
<a href = "index.htm">Navigator</a>
</h2>
      </nav>
    </div>
    <!--close header-->

    <div id="container">
      <div class="small_head">Small Head</div>
    </div>
    <!--close container-->

  </div>
  <!--close main-->
</body>

</html>
&#13;
&#13;
&#13; 请帮忙!

注意:我在另一个css中嵌入了字体,所以请忽略这些字体。

谢谢

3 个答案:

答案 0 :(得分:1)

这是因为<h1&gt; tag自然地在其上应用了使用font-size缩放的边距。你想在你的CSS中使用它:

h1 { margin:0 }

答案 1 :(得分:1)

h1元素的边距与em的字体大小有关。如果增加字体大小,则em相对于字体大小,因此,边距会增加。

答案 2 :(得分:1)

或者您可以使用max-height: <number of pixels> px代替h1 { margin:0 },但不会影响h1边距。