开发者

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

I'd like to clarify whether it's possib开发者_C百科le 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?


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


You can use display: inline-block.


You can use:

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

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

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


it works well on Edge and Chrome:

  width: fit-content;
  height: fit-content;


you can also use

word-break: break-all;

when nothing seems working this works always ;)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜