Centering a fixed element, but scroll it horizontally

谁都会走 提交于 2019-11-29 14:23:35

Ah, interesting question. I don’t think you can achieve that without JavaScript.

position: fixed means that the element is positioned relative to the viewport. You want that vertically, but you don’t want it horizontally. I don’t think there’s any way to achieve that in CSS.

Hussein

You can't have position:fixed on an overflow srolling content. You need to use JavaScript for this. i answered a similar question using jQuery at Fixed header inside scrolling block where a div is fixed even if content is scrolling by overflow.

Check working example at http://jsfiddle.net/VswxL/3/

Simple: http://jsbin.com/awaqug/edit#javascript,html,live

Edited a little bit by me, to make it easier to implement as you wish. The jquery code is not mine... Huh. This helped me, in no time...

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