How to make a div’s height 100% and expands to fit content with CSS?

Spread the love

Sometimes, we want to make a div’s height 100% and expands to fit content with CSS.

In this article, we’ll look at how to make a div’s height 100% and expands to fit content with CSS.

How to make a div’s height 100% and expands to fit content with CSS?

To make a div’s height 100% and expands to fit content with CSS, we use flexbox.

For instance, we write

#yourdiv {
  display: flex;
  width: 100%;
  height: 100%;
}

to make the div a flex container with display: flex;.

Then we make its width and height 100% to make it fit to its container.

Conclusion

To make a div’s height 100% and expands to fit content with CSS, we use flexbox.

Leave a Reply

Your email address will not be published.