[英]Trouble moving div down
我确定这很简单,但我今天已经研究了一段时间,只是无法弄清楚。
我想要做的就是将顶部 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
:
#template {
background: #fff;
width: 400px;
margin-top: 10%;
/* removed height property */
padding: 10px 0; /* adds padding to top and bottom evenly */
}
只是一个基本的 CSS 编辑....
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.