我有一個以百分比作爲值的div,以及需要適合的圖像。 應該調整寬度以適合div,而超過div的圖像的高度應該隱藏。將圖像調整爲div
(更清晰的視覺解釋)
this is what I have so far(編輯:粘貼錯誤的鏈接,我的壞)
的HTML:
<div class="wrap">
<img class="imgofcrap" src="http://physictourism.com/wp-content/uploads/2011/10/Grand-Canyon-National-Park-Arizona.jpg" />
</div>
的CSS:
div.wrap {
width: 20%;
height: 5%;
overflow:hidden;
border: 2px solid black; }
img.imgofcrap{
width: 100%;
height: auto; }
像這樣的事情? [DEMO](http://jsfiddle.net/Ruddy/5UJRB/5/)你也使用百分比作爲高度,但div沒有什麼可以獲得的高度。如果你想使用它,你需要設置'html,body {height:100%; }' – Ruddy
我喜歡你有你想要的手繪圖片。感謝您的努力。 – xDaevax
背景圖像會比內嵌圖像更好。 –