I've found a solution that works for me:
#myDiv { background: red; width: 100px; height: 100px; margin-top: -50px; margin-left: -50px; position: absolute; top: 50%; left: 50%; }
<div id="myDiv"></div>
However, the issue is that when I scroll down the page, the div loses its centered position since it is based on the original viewport height, not the current one. I think I need to detect a scroll event on the document and dynamically update the div's position. Any suggestions on how to do that?
Essentially, I want the div to always stay in the center even as the user scrolls.
Is there perhaps a CSS-only solution for this?