I’d like to use the CSS property position:fixed to fix the position of an element but at the same time prevent the element from being positioned over my footer when the user scrolls to the bottom of the page. Is there a way of stopping an element from showing over a footer in this way?
Share
If you want the element to be fixed sometimes but not others you will need to use JavaScript to add/remove
position:fixedFirst of all set the element without
position:fixedso that it appears in the page above the footer where you want it once scrolled to the bottom.Then set a css class that when added to the element fixes its position, something like:
The following code uses jquery, detects the scroll position on the page, and adds/removes the
fixedclass accordingly: