我試圖建立一個網頁,一個包裝,這將是最大寬度窗口高度:700像素調整大小容器,最大寬度
理想情況下,該網頁將響應和調整圖像以適合窗口。我真的很難讓瀏覽器調整圖像和容器的大小來適應窗口高度。寬度看起來很好。最終,用戶不必向下滾動查看頁面。這可能沒有JavaScript?如果沒有,有人可以指引我正確的方向嗎?謝謝!代碼如下:
的jsfiddle:http://jsfiddle.net/LTchE/
<style type="text/css">
body, html {
height: 100%;
margin: 0px auto;
padding: 0px auto;
}
#wrapper {
height: auto;
min-height: 100%;
margin: 0px auto;
padding: 0px auto;
max-width: 600px;
background: #de291e;
}
.happyHolidays {
background: url('http://placehold.it/600x80') no-repeat center;
background-size: contain;
width: 90%;
height: 80px;
margin: 0 auto;
display: block;
}
.fromMe {
background: url('http://placehold.it/600x80') no-repeat center;
background-size: contain;
width: 90%;
height: 80px;
margin: 0 auto;
display: block;
}
.buttons {
text-align: center;
}
.snowperson {
text-align: center;
}
.snowperson img {
width: 100%;
}
</style>
</head>
<body>
<div id="wrapper">
<div class="happyHolidays"></div>
<div class="fromMe"></div>
<div class="snowperson">
<img src="http://placehold.it/650x750" name="snowperson" border=0>
</div>
<div class="buttons">
<a href="javascript:NextImage()">
<img src="http://placehold.it/150x50" alt="Next snowperson">
</a>
</div>
</div>
</body>
雖然,目標是讓容器垂直調整大小。因此,如果要調整視口的高度,則內容將根據視口的大小進行調整,並佔用視口高度的100%,同時遵守包裝器的寬度。您的示例在Chrome中看起來並不適合我。 – Pdnell
啊,很對。我沒有完全讓你的代碼工作。如果你看看上面的第二個鏈接,它現在就可以工作。 更具體地說,容器#wrapper水平縮放,但它的內容溢出頁面底部。如果要垂直縮放內容以使圖像的中心位於瀏覽器的中心,我可以向您展示如何執行此操作。 – Mechame
是的,我們的目標是縱向擴展......它應該完全響應窗口大小。 – Pdnell