2016-08-30 19 views
2

残りのスペースがページに沿って流れるときにdivのコンテナをすべて取得しようとしています。残りの上部スペースを埋めるために4番目のボックスを得る方法はありますか?ここで浮動小数点の空白が空白になる

は一例です:

.col { 
 
    float: left; 
 
} 
 
.col > div { 
 
    margin: 10px; 
 
    background-color: grey; 
 
} 
 
.one.col { 
 
    width: 8.33%; 
 
} 
 
.two.col { 
 
    width: 16.66%; 
 
} 
 
.three.col { 
 
    width: 25%; 
 
} 
 
.four.col { 
 
    width: 33.33%; 
 
} 
 
.five.col { 
 
    width: 41.66%; 
 
} 
 
.six.col { 
 
    width: 50%; 
 
} 
 
.seven.col { 
 
    width: 58.33%; 
 
} 
 
.eight.col { 
 
    width: 66.66%; 
 
} 
 
.nine.col { 
 
    width: 75%; 
 
} 
 
.ten.col { 
 
    width: 83.33%; 
 
} 
 
.eleven.col { 
 
    width: 91.66%; 
 
}
<div style="width:960px;margin:0 auto;"> 
 
    <div class="col six"> 
 
    <div style="height:500px;">1</div> 
 
    </div> 
 
    <div class="col three"> 
 
    <div style="height:200px;">2</div> 
 
    </div> 
 
    <div class="col three"> 
 
    <div style="height:300px;">3</div> 
 
    </div> 
 
    <div class="col three"> 
 
    <div style="height:300px;">4</div> 
 
    </div> 
 
</div>

答えて

2

あなたがそこに動的なコンテンツを持つように計画している場合、動的に正しい位置を計算するだろういくつかのJSのロジックを投げる必要があるだろう。

divの高さがわかっている場合は、上の余白をマイナスして上に移動することができます。

.col { 
 
    float:left; 
 
    } 
 

 
    .col > div { 
 
    margin:10px; 
 
    background-color:grey; 
 
    } 
 

 
    .one.col{width:8.33%;} 
 
    .two.col{width:16.66%;} 
 
    .three.col{width:25%;} 
 
    .four.col{width:33.33%;} 
 
    .five.col{width:41.66%;} 
 
    .six.col{width:50%;} 
 
    .seven.col{width:58.33%;} 
 
    .eight.col{width:66.66%;} 
 
    .nine.col{width:75%;} 
 
    .ten.col{width:83.33%;} 
 
    .eleven.col{width:91.66%;}
 <div style="width:960px;margin:0 auto;"> 
 
    <div class="col six"> 
 
    <div style="height:500px;">1</div> 
 
    </div> 
 
    <div class="col three"> 
 
    <div style="height:200px;">2</div> 
 
    </div> 
 
    <div class="col three"> 
 
    <div style="height:300px;">3</div> 
 
    </div> 
 
    <div class="col three"> 
 
    <div style="height:300px; margin-top:-100px;">4</div> 
 
    </div> 
 
</div>

+0

残念ながら、私はあなたがJSを使用して、それを計算する必要があります – bryan

+0

のdivの高さを知ることができません。可能なすべてのケースをカバーしたいのであれば、簡単なことではないので、物事をすばやく実行したい場合はライブラリを探すことをおすすめします。しかし、それを実装するためのきちんとした練習です。 –

+0

注文が重要でない場合は、列に沿ってコンテンツを分割することもできます。しかし、これらのボックスの高さについてわからない場合は、結果が不均一になる可能性があるため、問題をあまりにも解決しません。 –