css align div center of page code example

Example 1: center div horizontally and vertically

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

Example 2: how to align elements horizontally in css

.row {
  width: 100%;
  display: flex;
  flex-direction: row;
  justify-content: center;
}
.block {
  width: 100px;
}

Example 3: css align center

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

Example 4: how to center a div

margin:auto

Example 5: how to align elements horizontally in css

<div class="row">
  <div class="block">Lorem</div>
  <div class="block">Ipsum</div>
  <div class="block">Dolor</div>
</div>

Tags:

Html Example