我试图将另一个 div 内的 div 向下移动一点,但是当我使用时
margin-top: 10px;
它在顶部形成一个白色间隙。 html 如下:
<div id="topb">
<div id="selection">
</div>
</div>
CSS 如下:
#topb {
background: url(images/tomato-background.jpg) no-repeat fixed;
background-size: cover;
height: 100%;
width: 101%;
margin-left: -10px;
}
#selection {
background-color: #4d4d4d;
width: 60%;
height: 500px;
margin: auto;
margin-top: 40px;
}
最佳答案
为此,您可以使用position:absolute
。这是代码:
#topb {
background: url(images/tomato-background.jpg) no-repeat fixed;
background-size: cover;
height: 100%;
width: 101%;
margin-left: -10px;
}
#selection {
background-color: #4d4d4d;
width: 60%;
height: 500px;
margin: auto;
position: absolute;
top: 40px; /*This is where it is changed as well as the line above*/
}
希望对您有帮助!我认为填充仍然会留下背景,所以这是一个更好的主意。
关于html - CSS 垂直向下移动 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40064712/