Center a position:fixed element <p>I would like to make a <code>position: fixed;</code> popup box centered to the screen with a dynamic width and height. I used <code>margin: 5% auto;</code> for this. Without <code>position: fixed;</code> it centers fine horizontally, but not vertically. After adding <code>position: fixed;</code>, it's even not centering horizontally.</p> <p>Here's the complete set:</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-css lang-css prettyprint-override"><code>.jqbox_innerhtml { position: fixed; width: 500px; height: 200px; margin: 5% auto; padding: 10px; border: 5px solid #ccc; background-color: #fff; }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="jqbox_innerhtml"&gt; This should be inside a horizontally and vertically centered box. &lt;/div&gt;</code></pre> </div> </div> </p> <p>How do I center this box in screen with CSS?</p>