力高< div>匹配图像 [英] Force height of <div> to match image

查看:29
本文介绍了力高< div>匹配图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个具有图像和< div> 并排的响应页面:

I'm building a responsive page that has an image and <div> side by side:

图像的宽度和高度保持不变,并随浏览器窗口扩展/收缩.

The width and height of the image retain their proportions and expand/contract with the browser window.

< div> 的宽度相同,但是我希望它与图像高度匹配.

The width of the <div> does the same, but I'd like it to match the image in terms of height.

有什么办法可以做到这一点?这是问题的提琴手: http://jsfiddle.net/alecrust/xwJHw/

Is there any way of achieving this? Here's a Fiddle of the problem: http://jsfiddle.net/alecrust/xwJHw/

推荐答案

您可以为此使用 display:table 属性.这样写:

You can use display:table property for this. Write like this:

section{
    display:table;
    width:100%;
}
.text-box,.image{
    display:table-cell;
    vertical-align:top;
}

选中此 http://jsfiddle.net/xwJHw/8/

注意: display:table 可以一直使用到IE8&以上.

Note: display:table works till IE8 & above.

这篇关于力高&lt; div&gt;匹配图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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