#sidebar
{
height: 200px;
position: fixed; /* Keep in position on scroll */
top: 50%; /* push down 50% of container */
margin-top: -100px; /* bring back up 50% height of this element */
}
#container
{
min-height: 200px;
_height: 200px; /* IE6 always acts as though height is min-height unless overflow: hidden */
}
2 回答
这就是你要找的东西 . 请注意,移动浏览器将忽略
position:fixed
,因此您需要使用一些js来使其适用于它们 . 另外,确保容器的最小高度为200px;您可能需要将
position: fixed;
添加到css中以使其不会移动 .