gpt4 book ai didi

html - CSS : Images scale aspect to fill

转载 作者:太空宇宙 更新时间:2023-11-04 13:04:31 24 4
gpt4 key购买 nike

我在一个由 div 包裹的 html 页面中有一个封面图像。div 大小始终为 width:100% height:33%。我希望任意图像都可以缩放以填充,而不会在任何屏幕尺寸和比例上被拉伸(stretch)。

我的 CSS 看起来像这样:

.headerImageWrapper{
position: relative;
width: 100%;
height: 33%;
overflow:hidden;
}

.coverImageCentered{
min-width: 100%;
min-height: 100%;
position: absolute;
top: -9999px;
bottom: -9999px;
left: -9999px;
right: -9999px;
margin: auto;
}

我的问题是图片尺寸不是满足这些条件的最小尺寸。

See the image to understand better

我是一名 iOS 开发人员,如果你现在它的工作原理基本上类似于 contentMode:缩放方面以填充

最佳答案

这就是你要找的..你可以在设备上测试这个解决方案 http://jsbin.com/joxinizo/4

源代码:

http://jsbin.com/joxinizo/4/edit

html, body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}

.bgd {
position: relative;
width: 100%;
height: 33%;
overflow: hidden;
}

.bgd-cover {
position: absolute;
top: 0;
left: -50%;
width: 200%;
height: 100%;
overflow: hidden;
}
.bgd-cover-img {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
min-width: 50%;
min-height: 13%;
}

UPD:我更新了我的答案

UPD2:

关于html - CSS : Images scale aspect to fill,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25231123/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com