我有以下问题:div元素更改父div的位置(边距)
我有一个背景图像的div元素,其位置完全像我想要的。但是当我添加一个子div时,它会改变。 (Theres在顶部有一个小幅度)
我想知道为什么会发生这种情况以及如何解决这个问题。
CSS代码:
body,html{
height:100%;
}
body {
margin: 0;
background-color: green;
background: url(../images/backround_red.png) no-repeat center center fixed;
background-size: cover;
}
div#mainWrapper {
position: relative;
text-align: center;
margin: auto;
width: 70em;
height:100%;
background: url(../images/header.jpg) no-repeat center center fixed;
background-size: cover;
padding-left: 4em;
}
div#loginWrapper {
position: relative;
top: 15%;
margin: 0;
}
截图:
没有childdiv:
与childdiv:
的jsfiddle: http://jsfiddle.net/DUtb4/
改变您孩子的'保证金top'为'浸轧top' –
你是什么意思? –
这通常是由子元素的margin-top造成的。请添加您的标记,也许jsFiddle,所以我可以肯定知道 –