align vertical center text div code example

Example 1: 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 2: align vertical center text div

display: flex;
align-items: center

Example 3: how to make the text vertically centered in css

/*attention, i used this code because i had to center a div with text in another div without text*/
div{
  position: relative;
  top: 25%;
  bottom: 25%;
}

Example 4: vertical align center text inside div

.center {
  height: 309px;
  line-height: 309px; /* same as height! */
}

Tags:

Misc Example