2016-11-23 118 views
-4

爲什麼我的導航欄不固定?我的意思是爲什麼當我向下滾動時它不會下降?爲什麼導航欄不固定?

這是代碼:

nav { 
 
    height: 40px; 
 
    width: 100%; 
 
    background: #455868; 
 
    font-size: 11pt; 
 
    font-family: 'PT Sans', Arial, sans-serif; 
 
    font-weight: bold; 
 
    position: relative; 
 
    border-bottom: 2px solid #283744; 
 
} 
 
nav ul { 
 
    padding: 0; 
 
    margin: 0 auto; 
 
    width: 600px; 
 
    height: 40px; 
 
}
<nav class="clearfix"> 
 
    <a href="#" id="pull">Menu</a> 
 
    <ul class="clearfix"> 
 
    <li><a href="#">Home</a></li> 
 
    <li><a href="#">How-to</a></li> 
 
    <li><a href="#">Icons</a></li> 
 
    <li><a href="#">Design</a></li> 
 
    <li><a href="#">Web 2.0</a></li> 
 
    <li><a href="#">Tools</a></li> 
 
    </ul> 
 
</nav>

+1

您在這裏沒有任何固定位置......所以 – DaniP

回答

1

試試這個:)希望這將對您有所幫助

nav { 
    height: 40px; 
    width: 100%; 
    background: #455868; 
    font-size: 11pt; 
    font-family: 'PT Sans', Arial, sans-serif; 
    font-weight: bold; 
    position: fixed; 
    border-bottom: 2px solid #283744; 
} 
0

更改CSS來

position: fixed; 

全碼:

nav { 
    height: 40px; 
    width: 100%; 
    background: #455868; 
    font-size: 11pt; 
    font-family: 'PT Sans', Arial, sans-serif; 
    font-weight: bold; 
    position: fixed; 
    border-bottom: 2px solid #283744; 
} 
nav ul { 
    padding: 0; 
    margin: 0 auto; 
    width: 600px; 
    height: 40px; 
} 
+0

非常多!我很白癡,我沒有看到它。另外如果有人希望酒吧的頂部邊距爲0,他需要放上:「top:0;」 – MrAndrew