我想實現日益流行的設計 - 水平對齊兩個50%寬度divs(.tile),但其內容跨兩個div限制爲整個寬度(等於站點其餘部分的頁面包裝,例如1200px)。我讓它們向左浮動以實現水平對齊,每個都有對比的顏色。在2個div上畫一個居中的「覆蓋」包裝。希望下面的代碼解釋了我的設置:包含50%寬度水平divs到整體包裝寬度(1200px)的內容
CSS
.full-width-row {
width: 100%; // 100% of entire page so child divs bg color will stretch
padding: 0;
margin: 0;
overflow: hidden;
height: auto;
position: relative;
}
.tile {
width: 50%;
float: left;
height: 100%;
margin-bottom: -99999px;
padding-bottom: 99999px // hack to fill height of parent
}
.tile-content {
padding: 5%;
}
.left {
background: #FFC15E;
}
.right {
background: #3E7F72;
}
HTML
<div class="full-width-row">
<div class="tile left">
<div class="tile-content">
//CONTENT LEFT
</div>
</div>
<div class="tile right">
<div class="tile-content">
//CONTENT RIGHT
</div>
</div>
</div>
這裏的父(。全寬行)是整個窗戶的100%,所以BG 2個子div的顏色將會延伸整個頁面。這是我想要在最大定義的寬度(等於1200px)內表現這些孩子的內容。有沒有人建立過類似的佈局或對如何實現這一目標有任何建議?
我想右邊的div永遠不會是一個問題,因爲它總是在1200px的包裝空間中,但左手將繼續在更大的屏幕上左移。
這是一個很難解釋的問題,需要一秒鐘的時間才能親自展示 - 就好像一個以兩個爲中心的「覆蓋」包裝孩子divs限制他們1200px – Andyjm
嗯 - 這並不真正描述它好多了,我害怕....如果你可以添加你想要的結果的圖像,也許? – Johannes
怎麼樣,限制左側從中心對齊600px(半個'包裝'寬度)? – Andyjm