Is it really impossible to make a div fit its size to its content?

Gabriele Cirulli picture Gabriele Cirulli · May 5, 2011 · Viewed 131.1k times · Source

I'd like to clarify whether it's possible or not to make a div fit its size based on the content's size without having to make elements float or having to make their position absolute. Is it possible?

Answer

Robert Koritnik picture Robert Koritnik · May 5, 2011

CSS display setting

It is of course possible - JSFiddle proof of concept where you can see all three possible solutions:

  • display: inline-block - this is the one you're not aware of

  • position: absolute

  • float: left/right