Horizontally fix element
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.
精彩评论