center vertically text code example

Example 1: css align items vertical center

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

Example 2: css align text vertically

/* HTML: */
<div class="text">
lorem ipsum
</div>


/* CSS: */
.text {
vertical-align: middle;
/*can take any value of:
baseline | sub | super | text-top | text-bottom | middle | top | bottom | <percentage> | <length> */
}

Example 3: css vertical align items in div

.flex-center-vertically {
  display: flex;
  justify-content: center;
  flex-direction: column;
  height: 400px;
}

Example 4: css center

// example 1 
div { display: grid; place-items: center; }

// example 3
div{ display:flex; align-items:center; }

// example 3
div { width: 100%; margin: 0 auto; }

Tags:

Html Example