Ashley Cameron Design

Ashley Cameron Design

Shop the Creative Design Market

Good morning

Centering a Fixed-Sized Element

CSSSnippets

About a 1 minute read

"Learn from yesterday, live for today, hope for tomorrow. The important thing is not to stop questioning."

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