最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Always-on-top header - Stack Overflow

programmeradmin3浏览0评论

I want to add a always-on-top header like the new twitter does. Explanation: When the user scrolls down the page, I want the header to stay on top of the window.

Somebody know a script that does that? Or can target me how can I do it?

I want to add a always-on-top header like the new twitter does. Explanation: When the user scrolls down the page, I want the header to stay on top of the window.

Somebody know a script that does that? Or can target me how can I do it?

Share Improve this question asked Dec 7, 2010 at 10:12 ChiefChief 231 silver badge3 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 5

You can use position: fixed; on the header.

<div id="header">
content goes here.
</div>

and the CSS:

#header { position: fixed; z-index: 9999; top: 0; left: 0; }

You need to give your header a position of fixed to make it visible throughout the page. And set the top value appropriately along with width.

Example:

#header{
  position:'fixed';
  top:0;
  width:800px;
}

Use position:fixed on the header in its CSS.

Also, dont forget to set the left and top attributes to where you want it to go :)

发布评论

评论列表(0)

  1. 暂无评论