如何使div具有相同的宽度和高度的内容? [英] How do I make a div have the same width and height of its content?

查看:109
本文介绍了如何使div具有相同的宽度和高度的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我在 div 中有一个 img 元素,如何使

= div

浮动div会使用CSS?

= div



你可能需要使用 clear



另一种方法是使用 inline-block


Let's say I have an img element inside a div, how do I make the div have the same width and height of its content using CSS?

解决方案

Floating the div would make it shrinkwrap and so the div would only have room for the content inside.

You will probably need to use clear on the elements coming afterwards.

Another way would be to use inline-block.

这篇关于如何使div具有相同的宽度和高度的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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