[英]Make my css menu stay on top of the screen?
就像在http://facebook.com中一樣,它們有一個導航欄類型的東西,它停留在頁面頂部,我該如何使用我的代碼來做到這一點。 我有我的CSS高級菜單,除了那個問題。 好,這是我到jsfiddle的鏈接
CSS的主要部分
#cssmenu ul { margin: 0; padding: 0;}
#cssmenu li { margin: 0; padding: 0;}
#cssmenu a { margin: 0; padding: 0;}
#cssmenu ul {list-style: none;}
#cssmenu a {text-decoration: none;}
#cssmenu { height: 42px; background-color: rgb(35,35,35); box-shadow: 0px 2px 3px rgba(0,0,0,.4);}
現在,如果我沒有記錯的話,那么這部分必須完成,否則請檢查JsFiddle
將以下內容添加到菜單css中:
#cssmenu {
position: fixed;
left: 0;
top: 0;
width: 100%;
}
他們基本上就是這樣做的。
添加固定資產
#cssmenu {
position:fixed;
}
可以使用以下方法完成:
position:fixed;
只是想一想,您是否不需要添加z-index: 1000;
以便它浮動在頁面上的所有項目上?
使用此CSS將導航欄固定在頂部。
#cssmenu {
position:fixed;
top: 0;
margin:auto;
left: 0;
right: 0;
width: 100%;
}
這里是演示: http : //jsfiddle.net/SkuhZ/
是的,您可以添加z-index: 1000;
使它浮動於所有內容之上 就像上面的RLCJohn所說。
這三個就行了
position: fixed;
top: 0;
width: auto;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.