HTML fixed header bar when scroll

微笑、不失礼 提交于 2020-01-03 09:09:08

问题


I've written an example here

http://jsfiddle.net/R9Lds/

I want a header bar on the top of the page.

<p style="vertical-align: middle; color: white">Head Bar</p>

And when user scrolls down and up, the header bar will always be on the top.

But now it has an issue that the bottom of the page will be cut-off.

Just like the example above, the

"Title 3",

"Content 3.",

"Author: Alex"

will be cut-off.

Anyone has any ideas about this issue?

Thanks in advance.

Eric


回答1:


You actually can achieve it simpler than that. You only need to set your header div with position: fixed, and a 'push' div to, well... push the content down.

Take a look in this Fiddle




回答2:


You should set your header bar to position: fixed instead.

Example:

div.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
}

if you are concerned about the top of .home being cut off, you can also add a margin-top

http://jsfiddle.net/R9Lds/1/



来源:https://stackoverflow.com/questions/24878582/html-fixed-header-bar-when-scroll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!