I have a webpage on which I would like to scroll to a certain element.
That part works fine by using scrollIntoView
; but I would like to add a bit of space
In general it's not very straightforward (if we want behavior: smooth
), and will require messing with javascript in one way or another. For example you could use window.scrollTo and calculate necessary top position manually.
In some cases however you could visually achieve necessary effect by using CSS smartly. In your demo you can use padding-top
instead of margin and wrap content of the block into additional helper container.
Demo: https://codepen.io/anon/pen/OvKQLV