我有几张尺寸变化很大的图像。 某些图像可能小至50x100,其他图像可能大至4000x4000。缩小图像以适应div,但从不缩放
我想以原始尺寸显示这些图像(从不更大)或缩小到适合浏览器窗口内的尺寸。
使用背景图片属性我得到的图像始终适应浏览器里面,但如果浏览器比图像大我不能向上扩展阻止他们:
<div class="slide-pane" style="background-image: url(<insert url to image here>);"></div>
.slide-pane {
background-repeat: no-repeat;
background-size:auto;
position: absolute;
background-position: center;
background-repeat: no-repeat;
height: 80%;
width: 80%;
}
我有发现这些使用Javascript/jQuery的解决方案:
但我希望有一些CSS唯一的解决方案。
很好的答案,另见http://www.quirksmode.org/css/css2/#t07 – chim