我有一個佈局,其中容器有一個fixed height and width of 640px x 480px
。在這個容器裏面有3個div,top
,mid
和bot
。我希望這3個div適合容器內部,只要它們不會溢出容器。 top
和bot
格沒有固定的高度,而mid
應該適合推頂和機器人之間的空間。在具有固定高度和寬度的父級div上垂直安裝div
我已經嘗試過是這樣的:
HTML
<div class="main">
<div class="top">
</div>
<div class="mid">
<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/b/bf/Chestnut-breasted_Malkoha2.jpg/593px-Chestnut-breasted_Malkoha2.jpg" />
</div>
<div class="bot">
</div>
</div>
CSS
.main {
padding: 10px;
width: 640px;
height: 480px;
display: inline-block;
background: #000;
position: relative;
}
.top {
width: 100%;
height: 50px;
display: block;
background: #eee;
}
.mid {
width: 100%;
height: 100%;
display: block;
background: #333;
}
img {
max-width: 100%;
max-height: 100%;
margin: 0 auto;
display: block;
}
.bot {
width: 100%;
height: 50px;
display: block;
background: #ccc;
}
現在我proble m是在容器外部中間推動機器人。我怎樣才能讓他們適合容器沒有使用溢出:隱藏?提前致謝。
NOTE :
the image should fit inside the mid
container.
UPDATEtop
和bot
DIV可以包含段落,所以它沒有固定的高度。
您可以使用'計算()'這樣http://jsfiddle.net/J6QTg/2/雖然它不被一些真正的舊瀏覽器支持。 –