Say "Hello!"

  • This field is for validation purposes and should be left unchanged.

Centering a Fixed-Sized Element


1
2
3
4
5
6
7
8
9
div {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 400px;
  height: 300px;
  margin-top: -150px; /* 1/2 of your element height*/
  margin-left: -200px; /* 1/2 of your element width */
}

Back to Snippets Follow me on GitHub

Ashley Cameron logo
Blog