【发布时间】:2016-03-07 01:02:19
【问题描述】:
我有这段代码:
<body>
<div class="page-top">
*
</div>
<div class="page-bottom">
<div class="contentbox">
<h1>CONTENTBOX</h1>
</div>
</div>
</body>
这是样式表:
body {
margin-left: 0;
margin-right: 0;
margin-top: 0;
margin-bottom: 0;
}
div.page-top {
padding-bottom: 20%;
}
div.page-bottom {
padding-bottom: 80%;
background-image: url('http://hd.wallpaperswide.com/thumbs/fog_at_the_pink_house-t2.jpg');
}
div.contentbox {
background-color: red;
margin-top: 10%; <!PROBLEM>
}
问题是:如果我在 contentbox 顶部添加一个边距(请参阅代码),而不是只在“父”div 的顶行 (.page-bottom) 下方的百分之十,它只会创建两个 div 上方的空白区域。
为什么会发生这种情况?我真正想要的是内容 div 在所有边只有大约 20% 的边距,所以它是全屏 div (page-bottom) 中的一个较小的 div (contentbox)。
要清除问题: click here for the image
感谢您的帮助,如果您需要更多信息,我会为您提供!
【问题讨论】: