2015-10-02 22 views
5

私は絶対的なコンテナを持っています(絶対的なままでなければなりません)。固定された高さで、2リットルを内側に、1つを上に、そして2を底に配置する必要があります。両方のliの高さは可変で、下のものは絶対位置を使用してはいけません。2列、親の最初の上と2番目の列

構造は、あなたがどのようにそれを行うにはjsfiddle here

任意のアイデアをオスロ見ることができます

<div id="container"> 
<div id="top"> 
    top variable height 
</div> 
<div id="bottom">bottom variable height</div> 

のですか?ありがとう

+0

を、あなたは# 'の高さの後に'#のcontainer'の内部に残っているの幅を占有するために '#のbottom'をしたいですトップ 'を考慮に入れましたか? – BenM

+0

私は、css pieやその他のような追加のjqueryを使わなくてもIE8でどんな解決策も動作しなければならないことを忘れていました。 – Adyyda

答えて

3

これは、Flexプロパティを使用して行うことができます。

フィドル:https://jsfiddle.net/9vq8nkpc/

HTML

<div id="container"> 
    <div id="top"> 
     top variable height 
    </div> 
    <div id="bottom">bottom variable heighbottom variable heightbottom variable heightbottom variable heightbottom variable heightbottom variable heightbottom variable heightbottom variable heightbottom variable heightbottom variable heightbottom variable heightbottom variable heightbottom variable heightbottom variable heightbottom variable heightbottom variable heightbottom variable heightbottom variable heightbottom variable heightt</div> 
</div> 

CSS

#container { 
    border: 1px solid red; 
    height: 200px; 
    position: absolute; 
    display:flex; 
    flex-direction:column; 
    justify-content:space-between; 
} 
#top, #bottom { 
    border: 2px solid red; 
    background: #ccc; 
    width:80%; 
    display: inline-block; 
} 
+0

解決してくれてありがとうございます。ie8でもうまく動作するものが必要です - 残念ですが、これについて言及するのを忘れてしまいました - http://caniuse.com/#feat=flexbox – Adyyda

+0

ああ、それは事です。それについて申し訳ありません! – Jesse

2

それはHTMLを変更することができます場合は、ディスプレイを使用することができますコンテナやディスプレイ用のテーブル:テーブル - 追加のコンテナ用のセル、次に垂直方向に並べることができますn内容。最初の里を一番上に置くには、絶対的な配置を使用することができます。

#container { 
 
    border: 1px solid red; 
 
    height: 200px; 
 
    width: 90%; 
 
    position: absolute; 
 
    display: table; 
 
} 
 
#top, #bottom { 
 
    border: 2px solid red; 
 
    background: #ccc; 
 
    width:80%; 
 
    display: inline-block; 
 
} 
 

 
#top{ 
 
    position: absolute; 
 
    top: 0; 
 
    left: 0; 
 
} 
 

 
.table-cell{ 
 
    display: table-cell; 
 
    vertical-align: bottom; 
 
}
<div id="container"> 
 
    <div class="table-cell"> 
 
      <div id="top">top variable height</div> 
 
      <div id="bottom">bottom variable height</div> 
 
    </div> 
 
</div>

フィドルのデモ:http://jsfiddle.net/3bsa7hco/1/

+0

残念ながら、thisiはデスクトップとレスポンシブルデバイス用の複雑な垂直メガメニューの一部なので、構造を変更できません。とにかくこのソリューションをありがとう。 – Adyyda

0

あなたはbottomは、絶対位置を持つことができないことを書いていますが、topについて同じことを言いませんでした。その場合

、あなたはこれらのスタイルを使用することができますので、

#top { 
    position: absolute;   //so top won't affect bottom's placement 
} 

#bottom { 
    position: relative;   //relative to container 
    top: 100%;      //height of container ... 
    transform: translateY(-100%); //... minus height of bottom element 
} 

Fiddle

+0

これは、それをサポートしていないie8以外ではうまく見えます。http://caniuse.com/#feat=transforms2d - 申し訳ありませんが、ie8でネイティブで動作する必要があることを忘れてしまいました。ウェブサイト全体 – Adyyda

+0

これはフレックスソリューションの問題でもあります。あなたの最善の策は@Juliaのテーブルソリューションかもしれません。 –

+0

残念ながら、私はこのコードを使用しているメガメニューを台無しにするので、私は構造を変更することはできません。 – Adyyda

関連する問題