我确定这很简单,但我今天已经看了一段时间,就是想不通。
我想要做的就是将顶部 div“#template-nav”向下移动一点,以便在其上方有一些空白。我试过 margin-top 和 padding 但它就是不会向下移动。
我有下面的 jsfiddle 和代码,非常感谢能找出我在这里出错的地方。
https://jsfiddle.net/rufusbear/Lgx7eksa/
<div id="template">
<div class="template-row">
<div id="template-nav"></div>
</div>
<div class="template-row">
<div id="template-jumbo"></div>
</div>
<div class="template-row">
<div class="template-col-1"></div>
<div class="template-col-2"></div>
</div>
<div class="clearfix"></div>
<div class="template-row">
<div id="template-footer"></div>
</div>
</div>
#template {
background: #fff;
width: 400px;
height: 400px;
margin-top: 10%;
}
.template-row {
max-width: 380px;
margin: 0 auto;
}
#template-nav {
height: 40px;
background: #8dcdc1;
padding-top: 10px;
}
#template-jumbo {
height: 150px;
margin: 2% 0%;
background: #d3e397;
}
.template-col-1 {
height: 130px;
width: 48%;
float: left;
margin-right: 2%;
background: #fff5c3;
}
.template-col-2 {
height: 130px;
width: 48%;
float: left;
margin-left: 2%;
background: #fff5c3;
}
#template-footer {
height: 40px;
margin: 2% 0%;
background: #d3e397;
}
.clearfix:after {
content: '.';
clear: both;
display: block;
height: 0;
visibility: hidden;
}
谢谢大家
最佳答案
在 #template
中向顶部元素添加 margin-top 是行不通的,因为该元素的边距及其顶部子元素会相互影响。
但是你可以添加一个padding-top
到#template
:
关于html - 无法向下移动 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39428190/