Ashley Cameron Design

Ashley Cameron Design

Shop the Creative Design Market

Goodnight

Centering a Fixed-Sized Element

CSSSnippets

About a 1 minute read

"Design is not just what it looks like and feels like. Design is how it works."

Steve Jobs


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