开发者

CSS/JQuery menu navigation

What code or script am I looking for in order to sticky a menu to the top of the website even as the user scrolls down the page开发者_运维问答?


position: fixed

Only use this for horizontal menus though — otherwise links to document fragments will put the content you are linking to under the menu.

Consider not using this, scrolling back up to the top is easy, and screen real estate is valuable (especially on a small display, such as a laptop).


You are looking for fixed positioning.

#someMenu {
  position:fixed;
}

From the documentation position fixed:

Generates an absolutely positioned element, positioned relative to the browser window. The element's


#idOfElementToFix {
  position: fixed;
  top: 10px; /* 10px from top of browser viewport */
  right: 10px; /* 10px from right of browser viewport */
}

Bear in mind that this could easily end up covering other elements as the user scrolls the page, so it's best to leave an empty gutter for it to occupy.

Just as food for thought, here's a link to one of the better tutorials for such a thing, by Remy Sharp: jQuery for Designers

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜