Is it really impossible to make a div fit to your content?

I would like to clarify whether or not it is possible for a div to fit its size based on the size of the content, without having to do float elements or their absolute position. Is it possible?

+52
html width size
May 05 '11 at 19:30
source share
4 answers

CSS display customization

Of course, it is possible - JSFiddle is a proof of concept , where you can see all three possible solutions:

  • display: inline-block is the one you don't know about

  • position: absolute

  • float: left/right

+90
May 05 '11 at 19:36
source share
โ€” -

You can use display: inline-block .

+15
May 05 '11 at 19:35
source share

You can use:

 width: -webkit-fit-content; height: -webkit-fit-content; width: -moz-fit-content; height: -moz-fit-content; 

EDIT: None. see http://red-team-design.com/horizontal-centering-using-css-fit-content-value/

ALSO: http://dev.w3.org/csswg/css-box-3/

+9
May 14 '15 at 10:41
source share

you can also use word-break: break-all; when nothing works, it always works;)

+1
Oct 21 '16 at 7:15
source share



All Articles