让一个div适合其内容的大小真的不可能吗? [英] Is it really impossible to make a div fit its size to its content?

查看:101
本文介绍了让一个div适合其内容的大小真的不可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想澄清是否有可能根据内容的大小制作适合其大小的div,而不必使元素浮动或不必将其位置设置为绝对位置。是否可能?

解决方案

CSS display setting



当然,可能 - JSFiddle概念证明,您可以在
中看到所有三种可能的解决方案:


  • display:inline-block - 这是你不知道的


  • float:left / right


  • ul>

    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?

    解决方案

    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

    这篇关于让一个div适合其内容的大小真的不可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆