我有一个标题 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;
}
<div id="header">
<h1>Title</h1>
<ul id="navbar"></ul>
</div>
put overflow:auto
在父级中div
在此链接中查看更多内容 https://stackoverflow.com/questions/1394724/css-margin-top-when-parents-got-no-border
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)