2013-03-20 58 views
0

我確實有1個父級div和2個子div,我想要這2個子div將等於它的父級高度或每當1個子div的內容展開另一個子div時也將擴大。我喜歡這樣,當你放大或者出高度尺寸保持不變,或者任何你們知道一些技巧來爲它工作我會欣賞它,這裏是我的js小提琴改用%PX的http://jsfiddle.net/deftmagic/29Puw/4/如何繼承父級高度給它的孩子

<div class="content-wrapper"> 
    <div class="task-pane"> 
     <p>sample</p> 
     <p>sample</p> 
     <p>sample</p> 
    </div> 
    <div class="tbl-div"> 
     <p>sample</p> 
     <p>sample</p> 
     <p>sample</p> 
     <p>sample</p> 
     <p>sample</p> 
     <p>sample</p> 
    </div> 
</div> 


.content-wrapper{ 
background:#000; 
min-height:0; 
width:100%; 
    overflow:hidden; 
    } 
.task-pane{ 
    background:red; 
    height:100%; 
    width:20%; 
    float:left; 
    } 
.tbl-div { 
    background:green; 
    height:100%; 
    width:80%; 
    float:right; 
} 

注意:球員我已經搜索了一些相同的問題,它發生了一些使用表,但我的衝突是當我使用表標籤它不能提供添加div標籤內,我需要最多,所以請如果有任何解決方案,而不是表也許有些劇本我會欣賞它 - 感謝^^

+0

你想要什麼沒有JS是不可能的,除非你給父DIV特定的高度(至少一個百分比)。 – dezman 2013-03-20 01:12:48

+0

是的,我確實認爲,所以我希望你們中的一些人可以提供我任何謝謝.. – deftmagic 2013-03-20 01:27:42

+0

我不想發佈一個鏈接作爲答案,但這篇文章,[流體寬度相等高度列](http:// css -tricks.com/fluid-width-equal-height-columns/)有很多非常棒的技巧,除了發佈的答案之外,我認爲這對你很有用。 – 2013-03-20 02:36:54

回答

0

我不得不這樣做多次,並有幾個技巧,以取消這種情況,並根據情況而有所不同。對於這個實例,我會讓父親的大小,絕對小的孩子,另一個默認,所以它會導致容器自我調整大小。

.content-wrapper{ 
    background:#000; 
    min-height:0; 
    width:100%; 
    overflow:hidden; 
    position: relative; 
} 
.task-pane{ 
    background:red; 
    width:20%; 
    position: absolute; 
    top: 0; bottom: 0; 
} 
.tbl-div { 
    background:green; 
    width:80%; 
    float:right; 
} 

更新小提琴:http://jsfiddle.net/29Puw/9/

+0

我不認爲這個工作相同的夢想食客答案每當我添加內容div身高doesnt工作,但謝謝 – deftmagic 2013-03-20 03:58:52

+0

我看到只有左div不擴大其高度,但其他不。以及它做了一些技巧,我剛纔已經解決了它可能是你的,但我操縱父母的div而不是孩子,但我想你的答案是好的 - 感謝這個 – deftmagic 2013-03-20 04:27:47

0
.content-wrapper { 
    background:#000; 
    overflow:hidden; 
    position: relative; 
} 
.task-pane { 
    background:red; 
    min-height: 100%; 
    width: 20%; 
    left: 0px; 
    position: absolute; 
} 

和更新的fiddle

+0

i'對不起,我沒有找到它作爲解決方案,因爲當我添加一些內容的div大小不會遵循了...但我很感激它..謝謝.. – deftmagic 2013-03-20 01:24:05