center div on page code example

Example 1: center a div in css

.container {
  display: flex;
  justify-content: center;
  align-items: center;
}

Example 2: center div in middle of page

.centered {
  position: fixed;
  top: 50%;
  left: 50%;
  /* bring your own prefixes */
  transform: translate(-50%, -50%);
}

Example 3: css center image

.center {
  display: block;
  margin-left: auto;
  margin-right: auto;
}

Example 4: css align center

//HTML
Hello World
//CSS .parent { display: flex; justify-content: center; align-items: center; }

Example 5: css align items vertical center

.parent {
  display: flex;
  justify-content: center;
  align-items: center;
}

Example 6: how to make a division center css

position:absolute;
top:50%;
left:50%;
transform:translate(-50%,-50%);

Tags:

Misc Example