我有一个标题div作为我的包装div中的第一个元素,但是当我在标题div中向h1添加一个上边距时,它会将整个标题div向下推.每当我将上边距应用于页面上的第一个可见元素时,我都会意识到这种情况.
这是一个示例代码段.谢谢!
div#header{
width: 100%;
background-color: #eee;
position: relative;
}
div#header h1{
text-align: center;
width: 375px;
height: 50px;
margin: 50px auto;
font-size: 220%;
background: url('../../images/name_logo.png') no-repeat;
}Run Code Online (Sandbox Code Playgroud)
<div id="header">
<h1>Title</h1>
<ul id="navbar"></ul>
</div>Run Code Online (Sandbox Code Playgroud)