How to vertically align elements in a div with CSS?

Spread the love

Sometimes, we want to vertically align elements in a div with CSS.

In this article, we’ll look at how to vertically align elements in a div with CSS.

How to vertically align elements in a div with CSS?

To vertically align elements in a div with CSS, we use flexbox.

For instance, we write

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

to make the element with ID container a flex container with display: flex;.

Then we vertically align the items inside with align-items: center;.

Conclusion

To vertically align elements in a div with CSS, we use flexbox.

Leave a Reply

Your email address will not be published.