Categories
CSS

How to force child div to be 100% of parent div’s height without specifying parent’s height with CSS?

Spread the love

To force child div to be 100% of parent div’s height without specifying parent’s height with CSS, we use flexbox.

For instance, we write

.parent {
  display: flex;
  flex-direction: row;
}

.child {
  align-self: center; 
}

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

And then the children element should fill the parent’s height by default.

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 *