align center in css code example

Example 1: css align center

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

Example 2: css align items vertical center

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

Example 3: center with css

.parent {
  position: relative;
}
.child {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

Example 4: css align center

.center {
  margin: auto;
  width: 50%;
  border: 3px solid green;
  padding: 10px;
}

Example 5: center align css

text-align: center;

Example 6: align center css

margin: auto;

Tags:

Misc Example