Ashley Cameron Design

Ashley Cameron Design

Shop the Creative Design Market

Goodnight

Centering a Fixed-Sized Element

CSSSnippets

About a 1 minute read

"Life is like riding a bicycle. To keep your balance, you must keep moving."

Albert Einstein


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 */
}