使div与其内部的图像大小相同 [英] Making a div the same size as an image inside it

查看:95
本文介绍了使div与其内部的图像大小相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含以下代码的div

I have an div with the following code

HTML:

<div id='imgContainer'>
    <img src='/img/logo.png' id='imglogo'></img>
</div>

CSS

div#imgContainer {
    width: 250px;
    height: 250px;
    padding: 13px;
}

问题是用户可以编辑图像大小,颜色和其他一些东西,所以我希望div随着图像变大而变大.如果图像小于它,我希望div的宽度和高度为250px,但随着图像变大而变得更大.

The problem is the users can edit the image size, colour and some other things, so I want the div to get bigger as the image get bigger. I want the width and height of the div to be 250px if the image is smaller than it, but to get bigger as the image gets bigger.

该解决方案可以使用PHP,JavaScript,CSS或jQuery.

The solution can be in PHP, JavaScript, CSS or jQuery.

推荐答案

尝试一下:

div#imgContainer {
    min-width: 250px;
    min-height: 250px;
    padding: 13px;
    display: inline-block;
}

小提琴

感谢@ahren和@Mohsen

Thanks to @ahren and @Mohsen

这篇关于使div与其内部的图像大小相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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