jquery - 将图像调整为 div 的 100% 高度并保持纵横比

标签 jquery html css

Here is a quick sketch.

我想实现画廊 div 中的图像将是画廊 div 高度的 100% 并保持纵横比

图像会像您更改浏览器的大小一样调整大小。

这可能吗?

如有任何帮助,我们将不胜感激。

这是我目前所做的:www.nulaena.si/photob/。

最佳答案

是这样的吗?

        body {
            padding:0;margin:0;
        }
        #header {
            position: absolute;
            background: orange;
            top:0;
            left:0;
            width: 100%;
            height: 100px;
        }
        #footer {
            position: absolute;
            background: orange;
            bottom: 0;
            left: 0;
            width: 100%;
            height: 100px;
        }
        #middle {
            position: absolute;
            top: 100px;
            bottom: 100px;
            left: 0;
            width: 100%;
        }
        img {
            height:100%;
            width: auto;
        }

<div id="header">header</div>
<div id="middle">
    <img src="images/myImage.jpg" />
</div>
<div id="footer">footer</div>

关于jquery - 将图像调整为 div 的 100% 高度并保持纵横比,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2646740/

相关文章:

java - 更改 HTML 对话框的样式 (CSS)

javascript - 将 "click outside of menu to close"jQuery/Javascript 添加到具有 .toggle() 的菜单下拉菜单

html - 为什么不建议使用@import 来链接css?

php - 在 Laravel 5.3 中强制换行

html - 无法访问 $scope 模型

javascript - 带有不同图标的 Twitter Bootstrap 3 导航栏切换按钮

html - 带圆 Angular 的 CSS3 菜单栏,我想我弄乱了选择器

html - 悬停时自动滚动图像高于容器(更高的图像)

javascript - 关于如何在 Flowplayer 中使用 seek(time, [callback]) 的示例

jquery - 如何为所有div设置单独的事件