我的页面底部有一些文字,上面写着 Built By Me。我将它固定在距离窗口底部和左侧 35px 的固定位置,因此它会随着您滚动而移动。我真正想要的是垂直固定它,所以它会随着你上下滚动而移动,并且总是离窗口底部 35px,但它的位置离页面左边缘(不是屏幕)35px 所以它水平滚动时不会移动。我检查了这个解决方案 Position element fixed vertically, absolute horizontally但不幸的是,它似乎对我不起作用。仅供引用,我目前正在使用以下代码修复它的顶部和底部,效果很好(但在水平滚动时也会移动):
#sticky {
position: fixed;
bottom: 35px;
left: 35px;
width: 206px;
padding: 0;
font-size: 0.6875em;
}
*html #sticky {
position: absolute;
bottom: 0px;
}
<div id="sticky">
Built by Me
</div>
非常感谢您提供的任何指示,因为我这辈子都搞不懂如何将它固定在一个轴上?
戴夫
最佳答案
保持固定的div。
并有以下 javascript 代码来处理水平移动。
$(window).scroll(function(){
$('.fixed_div').css('left',-$(window).scrollLeft());
});
关于css - 我可以使用位置 : fixed vertically and and position: absolute horizontally? 吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4819828/