Search code examples
htmlsizewidth

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


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?


Solution

  • 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