Centering a fixed element, but scroll it horizontally

前端 未结 3 483
孤独总比滥情好
孤独总比滥情好 2020-12-21 00:36

Having some issues getting this to work. PLEEEEEEASE help.

I would like an element fixed to the top of the viewport, when the user scrolls down the page it remains a

相关标签:
3条回答
  • 2020-12-21 00:58

    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/

    0 讨论(0)
  • 2020-12-21 00:58

    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...

    0 讨论(0)
  • 2020-12-21 01:24

    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.

    0 讨论(0)
提交回复
热议问题