Hello Web Developers,

Using CSS what is the best way to expand a div to fit it's content?

I currently use overflow: auto but sometimes the div turns into a scrollable element which disrupts the design.
Can this be done in another way like height: max-content? Are there any other ways of going about this?

Recommended Answers

All 2 Replies

A div block will automatically set its width to fill the space. You should be able to set height: 100% to fill the height.

Oh, just a heads up. You also need to set all the parent elements to height 100% as well, up to and including the body element.

If you show your code I can take a look for ya.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.