开发者

Horizontally fix element

开发者 https://www.devze.com 2023-03-13 00:38 出处:网络
Using position:fixed fixes an element both verti开发者_开发问答cally and horizontally, but I want my element only to remain horizontally fixed. That is, I want it to scroll vertically with the rest of

Using position:fixed fixes an element both verti开发者_开发问答cally and horizontally, but I want my element only to remain horizontally fixed. That is, I want it to scroll vertically with the rest of the page.

Is there any CSS way of doing this? If not, would monitoring scroll offsets and then moving the element be the right approach?


I ended up doing something like this:

.fixThisHorizontally {
    position:absolute;
    z-index:100;
}

Then,

jQuery(window).scroll(function() {
    jQuery('.fixThisHorizontally').css('left', document.body.scrollLeft);
});

Thanks to all who answered.


 position:absolute;overflow-x: hidden; overflow-y: scroll;

did you try these


I don't think this is possible entirely with CSS. I would, indeed, use position:absolute and use JavaScript to change the top css value when the page is scrolled.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号