How to keep div in center-height when I resize the browser window?
I am trying to center in height a div, however it does not work when I resize the browser screen.
How to edit this to achieve the adjustable margin-top on resize?
Edit: The answer should be in js since flexbox won’t work on IE-9
Although you can easily do this with pure CSS, your bounty stated that you want a JS answer.
If you are interested in a pure CSS answer, see this answer that has multiple different methods on how to center elements vertically/horizontally.
You could simplify your jQuery to the following:
Then you could just place this within a
resize event listener and chain the
.resize() method in order to trigger the event initially when the browser loads.