3 回答

TA贡献1793条经验 获得超6个赞
实际上,这是有可能的,而公认的答案只涉及集中化,这是相当直截了当的。而且,您真的不需要使用JavaScript。
这将允许您处理任何场景:
设置一切,如果您想要定位:绝对在一个位置:相对容器,然后在div内创建一个新的固定位置divposition: absolute,但是不设置其顶部和左侧属性。然后,它将被固定在你想要的任何地方,相对于容器。
例如:
/* Main site body */
.wrapper {
width: 940px;
margin: 0 auto;
position: relative; /* Ensure absolute positioned child elements are relative to this*/
}
/* Absolute positioned wrapper for the element you want to fix position */
.fixed-wrapper {
width: 220px;
position: absolute;
top: 0;
left: -240px; /* Move this out to the left of the site body, leaving a 20px gutter */
}
/* The element you want to fix the position of */
.fixed {
width: 220px;
position: fixed;
/* Do not set top / left! */
}
<div class="wrapper">
<div class="fixed-wrapper">
<div class="fixed">
Content in here will be fixed position, but 240px to the left of the site body.
</div>
</div>
</div>
可悲的是,我希望这条线能解决我和Android的问题WebKit呈现框影模糊像素作为固定位置元素的边距,但它似乎是一个错误。
不管怎样,我希望这能帮上忙!
- 3 回答
- 0 关注
- 313 浏览
相关问题推荐
添加回答
举报