gpt4 book ai didi

css - 如何使高于容器的图像居中?

转载 作者:行者123 更新时间:2023-11-28 18:09:13 25 4
gpt4 key购买 nike

我已经搜索了一些与我的案例相关的解决方案,但所有问题都与我的案例不完全相同。

对于容器 (300x150),图像必须设置为 width:100%height:auto。我不知道在我的情况下上传图片的宽度是多少,所以我想我不能使用 background-image 作为解决方案

这是行不通的:

#image-container {
display: block;
position: relative;
width: 300px;
height: 150px;
overflow: hidden;
}
.img {
width: 300px;
height: auto;
position: absolute; /*this is for my working frame, can't change*/
}

演示链接: http://jsfiddle.net/bardirian/zPg5m/

---更新--

它适用于来自 btlr.com 的背景图像创意请参阅此处更新的演示: http://jsfiddle.net/bardirian/zPg5m/7/

当我尝试将其添加到我的 html 时,我发现另一个问题是 jquery 元素需要从 html 导入图像,所以我仍在寻找更好的 css 解决方案,但不是背景图像。

最佳答案

像这样的东西怎么样

<div id="image" class="clearfix blog-image" 
style="background: url('http://i.imgur.com/5d8taEj.jpg') center center no-repeat;
background-size: contain;
">


</div><br />

background-size: contain; - 这将与背景一起工作,我刚刚在你的演示中检查过它(尝试减小你的 div 的大小)

关于css - 如何使高于容器的图像居中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19037560/

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