![](/img/trans.png)
[英]Make an image placed in a div 100% width and 100% height of browser
[英]Adjust 100% height or width of image as per parent div width / height
我有一個動態/響應的div
圖像。 並希望按照DIV高度/寬度將圖像高度或寬度設置為100%。 我不想拉伸圖像。 寬度或高度都不應為100%。
這是我嘗試http://jsfiddle.net/CLrUS/的示例
像這樣給CSS圖片
.css{ max-width:100%;
max-height:100%}
此處的圖片采用父div的寬度。 在這里圖像不會拉伸,圖像會得到比例的高度和重量
范例: http : //jsfiddle.net/CLrUS/1/
用於增加高度:
.class img{
height: 100%;
width: auto;
}
而這只是寬度:
.class img{
height: auto;
width: 100%;
}
嘗試這個:
<img src="#your image#" onload="imgFitParent($(this));" style="width:inherit; height:inherit;">
<script type="text/javascript">
function imgFitParent(imgElemt)
{
if(imgElemt.parent().width() > imgElemt.parent().height()){
imgElemt.height("100%");
imgElemt.width('auto');
}else{
imgElemt.width("100%");
imgElemt.height('auto');
}
}
</script>
像這樣: JSFIDDLE
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.