Categories
CSS

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 weite

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

to make the elements with class container flex containers with display: flex;.

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

Conclusion

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

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *