我有一個複雜的佈局,其中有一個由動態高度的JavaScript生成的div,他被稱爲「.outer」。這個div有一些嵌套的div,最後導致一個名爲「.target」的div。我需要目標div處於「高度」的高度。我不想解決內部div,因爲他們是由我的JS框架生成的不同標記。只用flexbox乘以bested DIV,inner div全高 - 可能嗎?
我不想設定通過JS的高度,我無法設置位置,絕對的,也不在相對 「.outer」
HTML:
<div class="outer">
<div class="inner">
<div class="anotherInner">
<div class="target">
This div should be outer's height no matter how many divs are between target and outer like ".inner"
</div>
</div>
</div>
</div>
CSS:
body {
background: #000;
}
.outer {
background: #333;
height: 500px; /* this is not a pixel value, only for example*/
display: flex;
flex-direction: column;
flex-wrap: wrap;
justify-content: flex-start;
align-content: stretch;
align-items: stretch;
}
.inner {
background: #555;
}
.target {
background: #777;
order: 0;
flex: 1 1 auto;
align-self: auto;
}
示例:
http://codepen.io/anon/pen/akwWZK?editors=1100
不可能使用flexbox。 Flexbox僅適用於'display:flex'父項和直接子項。最好的辦法是使用'position:relative'到'.outer'和'position:absolute'到'.inner'。 –