How to make a div not larger than its contents with CSS?

Spread the love

Sometimes, we want to make a div not larger than its contents with CSS.

In this article, we’ll look at how to make a div not larger than its contents with CSS.

How to make a div not larger than its contents with CSS?

To make a div not larger than its contents with CSS, we can set the display property to inline-block.

For instance, we write

div {
  display: inline-block;
}

to set the display property of the div to inline-block to make the div’s dimensions fit the content.

Conclusion

To make a div not larger than its contents with CSS, we can set the display property to inline-block.

Leave a Reply

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