我有幾張尺寸變化很大的圖像。 某些圖像可能小至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