Is it really impossible to make a div fit its size

2019-01-13 07:20发布

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?

标签: html size width
4条回答
Rolldiameter
2楼-- · 2019-01-13 07:27

you can also use

word-break: break-all;

when nothing seems working this works always ;)

查看更多
萌系小妹纸
3楼-- · 2019-01-13 07:43
姐就是有狂的资本
4楼-- · 2019-01-13 07:45

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

查看更多
霸刀☆藐视天下
5楼-- · 2019-01-13 07:49

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/

查看更多
登录 后发表回答