Vertical & Horizontal center a fixed element

/ Published in: CSS
Save to your folder(s)

Center X and Y of fixed element, you must know the width and height

Copy this code and paste it in your HTML
  1. position:relative;
  2. height:600px;
  3. top: 50%;
  4. margin-top: -300px; /* minus half the height */
  5. left:50%;
  6. margin-left:-300px /* minus half the width */
  7. width:600px;

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.