我创建了一个页面,当我注意到当我增加或减少标题的字体大小时,周围的空间会急剧增加。我没有填充的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>
请帮助!
注意:我在另一个css中嵌入了字体,所以请忽略这些字体
谢谢
这是因为<h1
>标签自然有一个根据font-size缩放的边距。你想在你的css:
h1 { margin:0 }
h1元素的边距通过em与字体大小相关。如果您增加字体大小,em与字体大小相关,因此,边距也会增加。
或者您可以使用max-height: <number of pixels> px
代替h1 { margin:0 }
,您将不会影响h1边距