Ashley Cameron Design

Ashley Cameron Design

Shop the Creative Design Market

Good morning

Centering a Fixed-Sized Element

CSSSnippets

About a 1 minute read

"It is the supreme art of the teacher to awaken joy in creative expression and knowledge."

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