标题不固定

时间:2013-08-30 10:33:24

标签: css

大家好我正在设计一个网页。我想要一个固定的标题。

为此我设置了position: fixed;。但是当我在网页中添加一个花药<div>并为它设置一些上边距时,标题的边距也会改变,这里是我的标题CSS

#header {
  width:100%;
  height:35%;
  color:#303030;
  postion:fixed;
}

并且标题下面的div的CSS是这个

#content {
  width:250px;
  height:350px;
  margin-left:50px;
  margin-top:75px;
  border-style:solid;
  border-color:#303030;
  border-width:1px;
}

我的HTML

<div id="header">
Predufu
</div>
<div id="content">
</div>

我在这个问题中添加了我的html的一小部分

现在在#content我设置margin-top: 75px;但是这样,标题的边距也会改变,为什么会发生这种情况请告诉我我的网页需要一个固定的标题

2 个答案:

答案 0 :(得分:0)

我改变了一些CSS属性并且它有效。首先我尝试使用position:absolute,但它也适用于position:fixed。

#header {
    position: absolute;
    top: 10px;
    left: 10px;
    width:100%;
    height: 100px;
    color:#303030;
    background-color: #aaa;
}

#content {
    position: absolute;
    top: 120px;
    left: 50px;
    background-color: #eee;
    width:250px;
    height:350px;
    border: 1px solid 303030;
}

请看这里的位置:固定 - &gt; http://jsfiddle.net/NicHope/n32Mu/ 这是你要找的吗?

答案 1 :(得分:-1)

尝试将其最高位置添加到标题中。你的拼写位置也错了。

试试这个:

#header {
  width:100%;
  height:35%;
  color:#303030;
  position:fixed;
  top: 0px;
}

JSfiddle Example

相关问题