![](/img/trans.png)
[英]Image Set Width Height Attributes in HTML, Set Width 100% in CSS
[英]HTML CSS how to set height 100%, width when expand 100% but when narrow the width it doesn't display full width
我不確定如何實現自己的目標。 很難完全描述我的意思,但是我有一個例子。
情況當屏幕水平擴展時,圖像設置為屏幕寬度的100%,但是當屏幕縮小時,圖像不會完全顯示,而是將高度保持為100%。
我在下面附上一個示例,這正是我在考慮的問題。
http://www.therentscene.com/
<script>
var container=window;
var image=document.getElementById("backimage")
if (container.height() > container.width()) {
image.css({height: container.height(), width: ''});
} else {
image.css({height: '', width: container.width()});
}
</script>
使用js / jQuery並找到max(container.h, container.w)
並將該值應用於圖像本身
if (container.height() > container.width()) {
image.css({height: container.height(), width: ''});
} else {
image.css({height: '', width: container.width()});
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.