gpt4 book ai didi

css - 绝对div内的图像高度?

转载 作者:行者123 更新时间:2023-11-28 10:17:24 25 4
gpt4 key购买 nike

Windows 版 Safari 无法在绝对定位的 div 中正确计算 img 高度。样式在 Chrome 和 Firefox 上运行良好。

http://jsfiddle.net/Wh2Tr/

HTML:

<div class="image">
<div class="image-inner">
<img src="http://lorempixel.com/400/200" />
</div>
</div>

CSS:

.image {
position: relative;
max-width: 100%;
height: 0;
padding-bottom: 75%;
}

.image-inner {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 0;
}

.image img {
width: auto;
max-height: 100%;
margin: 0 auto;
display: block;
}

注意事项:

  1. 这是对 HTML 的简化。有多个不同大小的图像需要具有相同的高度(因此使用 width:100%;height:auto; 将不起作用)
  2. 这需要自适应/响应,所以我无法为图像或容器设置明确的宽度或高度。

最佳答案

同样的问题,我用过jquery。直到现在我找不到任何解决方案:

$('.image-inner').css('height','100%').height($('.image-inner').height());

关于css - 绝对div内的图像高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19843513/

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