2013-04-24 85 views
0

我有一個容器和兩列的頁面。我的結構看起來這浮體和襯墊 - 等高

<div id="page"> 
    <div id="left"></div> 
    <div id="right"></div> 
</div> 

這裏是CSS

#page { 
    min-height: 100%; 
    height: 100%; 
    width: 90%; 
    font-size: 100%; 
    margin: 0 auto 0 auto; 
    padding: 0; 
    font-size: 1em; 
    position: relative; 
} 

#left { 
    background-image: url("../images/layout/background.png"); 
    width: 198px; 
    min-height: 100%; 
    float: left; 
} 

#right { 
    margin-left: 230px; 
    min-height: 100%; 
    background-color: #FFFFFF; 
    border: 1px solid red; 
    padding: 150px 20px 0px 20px; 
    text-align: justify; 
} 

在與之前的代碼#page元素不伸展至底部的時刻,同樣沒有了#left。如果我從#right中刪除填充物,#page#left#right的高度相同。

我該如何解決這個問題?

回答

0

所以有幾種方法可以解決這個問題。如果您希望只有兩列具有不同背景並且都到達其容器底部的列,則可以使用垂直重複的背景圖像或css3漸變。我成立了這個範例:

http://jsfiddle.net/29wBn/1/

通知的#page元素

#page { 
    background: -moz-linear-gradient(left, #b2f8ff 0%, #b2f8ff 50%, #9effaf 50%, #9effaf 100%); /* FF3.6+ */ 
    background: -webkit-gradient(linear, left top, right top, color-stop(0%,#b2f8ff), color-stop(50%,#b2f8ff), color-stop(50%,#9effaf), color-stop(100%,#9effaf)); /* Chrome,Safari4+ */ 
    background: -webkit-linear-gradient(left, #b2f8ff 0%,#b2f8ff 50%,#9effaf 50%,#9effaf 100%); /* Chrome10+,Safari5.1+ */ 
    background: -o-linear-gradient(left, #b2f8ff 0%,#b2f8ff 50%,#9effaf 50%,#9effaf 100%); /* Opera 11.10+ */ 
    background: -ms-linear-gradient(left, #b2f8ff 0%,#b2f8ff 50%,#9effaf 50%,#9effaf 100%); /* IE10+ */ 
    background: linear-gradient(to right, #b2f8ff 0%,#b2f8ff 50%,#9effaf 50%,#9effaf 100%); /* W3C */ 
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#b2f8ff', endColorstr='#9effaf',GradientType=1); /* IE6-9 */ 
    overflow:hidden; /* make the container wrap the floated contents */ 
} 

其回落的#page元件上的漸變背景被分配左側欄的顏色和右列收到它自己的顏色。

Chris Coyer寫了一篇很棒的文章,展示了幾種不同的方法。 http://css-tricks.com/fluid-width-equal-height-columns/