如何保持标题静态

如何保持标题静态

本文介绍了如何保持标题静态,总是在滚动时顶部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何保持我的 #header {
position:fixed;
}

#content {
margin-top:100px;
}

在此示例中, #content 从 #header 开始100px,但随着用户滚动, #header 保留在原位。当然不用说,你会想要确保 #header 有一个背景,以便其内容实际上可以看到,当两个 div 重叠。请查看位置属性:


How would I go about keeping my header from scrolling with the rest of the page? I thought about utilizing frame-sets and iframes, just wondering if there is a easier and more user friendly way, what would be the best-practice for doing this?

解决方案

Use position: fixed on the div that contains your header, with something like

#header {
  position: fixed;
}

#content {
  margin-top: 100px;
}

In this example, when #content starts off 100px below #header, but as the user scrolls, #header stays in place. Of course it goes without saying that you'll want to make sure #header has a background so that its content will actually be visible when the two divs overlap. Have a look at the position property here: http://reference.sitepoint.com/css/position

这篇关于如何保持标题静态,总是在滚动时顶部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 18:31