在标题内导航,位置固定?

时间:2013-11-11 15:32:33

标签: css css3 css-position

我有一个100%宽度的标题,以及一个带有980px

的导航标题

现在我想给头部和导航器固定位置。 我尝试过以下代码,但无法得到我想要的东西 请帮帮我,

我的header.css

width:100%;
height:60px;
background: #ffffff;
position:fixed;
z-index:999;`

和我的nav.css

background: #ffffff;
height: 60px;
text-align:center;
position:fixed;
z-index:99; 

.nav ul

margin:0;
padding:0;

.nav li

   display: inline-block;
   list-style-type: none;
   vertical-align:middle;`

.nav li a

font-size: 16px;
color: black;
display: block;
line-height: 60px;
padding: 0 10px;
text-decoration: none;

2 个答案:

答案 0 :(得分:0)

如果导航位于标题内,您的nav.css中不需要position:fixed,则还应删除z-index。如果没有帮助,更清楚地描述问题和你正在使用的HTML将会有所帮助。

答案 1 :(得分:0)

@Fastnto,你想要的是这样的吗?

http://jsfiddle.net/alexandrecanijo/NBp8F/

我已经更改了原始CSS的某些部分以显示标题(#ccccccc)和nav(#000000),并添加了.content和足够的lorem ipsum,以便您能够看到导航。 但是,CSS可能会在某些部分被清理和重构......没有改变这样做......

希望这有帮助。

html,body, p {
    margin: 0;
    padding: 0;
    border: 0;
    font: 14px arial;
}
.header {
    width: 100%;
    height: 80px;
    background: #cccccc;
    position: fixed;
    z-index:999;
    margin: 0;
    clear: both;
    top: 0;
}

.nav {
    background: #000000;
    height: 60px;
    text-align:center;
    z-index:99;
}

.nav ul {
    margin:0;
    padding:0;
}

.nav li {
    float: left;
    list-style-type: none;
}
.nav li a {
    font-size: 16px;
    color: #fe6700;
    display: block;
    line-height: 60px;
    padding: 0 10px;
    text-decoration: none;
}
.nav li a:hover {
    color: #000000;
    background: #fe6700;
}
.content {
    margin-top: 80px;
}
相关问题