如何获得DIV高度自动调整背景的大小? [英] How to get div height to auto-adjust to background size?

查看:86
本文介绍了如何获得DIV高度自动调整背景的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何获得一个div来自动调节,以我为它设置没有设置特定高度的背景大小(或最小高度)呢?

How do I get a div to automatically adjust to the size of the background I set for it without setting a specific height (or min-height) for it?

推荐答案

另外,也许是低效的,解决办法是将包括设置为<$一个 IMG 元素下的图像C $ C>可见性:隐藏; 。然后让背景图片周围DIV一样的形象。

Another, perhaps inefficient, solution would be to include the image under an img element set to visibility: hidden;. Then make the background-image of the surrounding div the same as the image.

这将设置周边div来在 IMG 元素的图像大小,但其显示为背景。

This will set the surrounding div to the size of the image in the img element but display it as a background.

<div style="background-image: url(http://your-image.jpg);">
 <img src="http://your-image.jpg" style="visibility: hidden;" />
</div>

这篇关于如何获得DIV高度自动调整背景的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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