如何根据另一个div的边距定位div?

时间:2014-05-02 19:14:19

标签: html css

我有两个div。

<div class="header"></div>

<div class="container">
<p>This is the container.</p>
</div>

这是css代码。

.header{
    width:100%;
    height:100px;
    position:fixed;
    background-color:#eee;
}
.container{
    margin:0 auto;
    margin-top:100px;
    margin-bottom:100px;
}

为什么标题会下降,即使我在容器上放了一个保证金?有人可以建议我像其他常用页面一样在容器中有一个固定的标题和其他东西吗?

2 个答案:

答案 0 :(得分:1)

尝试在标头css中使用top:0http://jsfiddle.net/Nh3Tf/

答案 1 :(得分:1)

您需要添加top:0;left: 0;

.header{
width:100%;
height:100px;
position:fixed;
background-color:#eee;
top: 0;
left: 0;

}

看看here