2016-12-01 29 views
0

divsの高さに関する問題を扱っています。それは単にコンテンツを考えても拡張しません。Divの高さが伸びない

コンテンツ厥: Thats the content

とコンテナのthats: enter image description here

あなたが見ることができるように、コンテナは、それが含まれているにもかかわらず、かなり短いです私は最初にあなたのスクリーンショット上の問題をお見せしましょう長い内容の要素。私は「オーバーフロー:オート」のようなものを試しました。

HTML::

<div id="menu2" class="container"> 
     <div id="mytextbox" class="col-sm-12 col-xs-12"> 

      <h2 id="h2Box1" style="visibility: visible">Text from the box1</h2> 
      <h2 id="h2Box2" style="visibility: hidden">Text from the box2</h2> 
      <h2 id="h2Box3" style="visibility: hidden">Text from the box3</h2> 
      <h2 id="h2Box4" style="visibility: hidden">Text from the box4</h2> 

      <p id="pBox1" style="visibility: visible">Paragraph from the box1</p> 
      <p id="pBox2" style="visibility: hidden">Paragraph from the box2</p> 
      <p id="pBox3" style="visibility: hidden">Paragraph from the box3</p> 
      <p id="pBox4" style="visibility: hidden">Paragraph from the box4</p> 

     </div> 
     <div id="box1" class="col-sm-6 col-xs-3 mybox active-box"> 
      <span class="hidden-xs">BOX NAME 1</span> 
      <span class="visible-xs">1</span> 
     </div> 

     <div id="box2" class="col-sm-6 col-xs-3 mybox"> 
      <span class="hidden-xs">BOX NAME 2</span> 
      <span class="visible-xs">2</span> 
     </div> 
     <div id="box3" class="col-sm-6 col-xs-3 mybox"> 
      <span class="hidden-xs">BOX NAME 3</span> 
      <span class="visible-xs">3</span> 
     </div> 
     <div id="box4" class="col-sm-6 col-xs-3 mybox"> 
      <span class="hidden-xs">BOX NAME 4</span> 
      <span class="visible-xs">4</span> 
     </div> 
    </div> 

CSS:

@media screen and (min-width: 992px) { 

.container { 
    display: flex; 
    flex-flow: row wrap; 
    width: 40%; 
    margin-left: 30%; 
    margin-right: 30%; 
    padding-left: 0; 
    padding-right: 0; 
} 

#menu2 { 
    position: relative; 
    padding: 5% 0; 
} 

.mybox { 
     padding-top: 3%; 
     padding-bottom: 3%; 
     width: 30%; 
     font-size: 1.5em; 
    } 

    #mytextbox { 
     position:absolute; 
     top: 30%; 
     z-index: 2; 
     order: 3; 
     background: 
      linear-gradient(
       rgba(255, 255, 255, 1), 
       rgba(255, 255, 255, 0.7) 
       ), 
       url('./../images/Pattern.png') bottom no-repeat; 
    } 

    #box1 { 
     position: absolute; 
     top: 5%; 
     order: 1; 
     background-color: rgb(66,142,158); 
     margin-right: 25%; 
     margin-left: -28%; 
    } 

    #box2 { 
     position: absolute; 
     order: 2; 
     background-color: rgb(196,52,52); 
     margin-left: 30%; 
     right: -28%; 
     top: 5%; 
    } 
    #box3 { 
     position: absolute; 
     order: 4; 
     background-color: rgb(223,187,66); 
     margin-right: 30%; 
     margin-left: -28%; 
     bottom: 5%; 

    } 
    #box4 { 
     position: absolute; 
     order: 5; 
     background-color: rgb(80,139,97); 
     margin-left: 30%; 
     right: -28%; 
     bottom: 5%; 
    } 

} 

お持ちの場合はそれだけでいくつかのスクロールバー..私はここで行うことができます他に何かわからない。これが最も重要なコードですが追加されます任意のアイデア、助けてください!

UPDATE: これは私が達成しようとしているものです:

aim

ので、私はちょうど私がそこにいくつかの問題を持って実現したときに巨大な「テキストボックス」を中心にこれらのボックスを設定し、ときに私ましたそれらの小さなカラフルなボックスを底に置いてください。実際には "テキストボックス"の底ではなく、親( "コンテナ")の底です。物事は..私は右に "テキストボックス"ので、彼らの底は等しくする必要がありますので、私は簡単にその周りの小さなボックスを設定することができますコンテナを展開したい。

+0

あなたは「ボックス1」について話していますか?それは含まれているテキストよりも背が高い。問題は何ですか? –

+1

あなたはそれが位置のためだとは思わない:絶対; ? –

+0

ここにはJavaScriptがタグ付けされていますか? – Rob

答えて

1

これはあなたが望むものであるかどうかわかりません。しかし、

position of `#mytextbox` div is absolute so container will never get its height. 

私はここでは、より小さい画面上のメディアクエリを削除しました。あなたはこれを試すことができますから#mytextbox css

以下のコードスニペットを実行してください。アウトプットウィンドウをフルスクリーンに拡大すると、より大きなスクリーンがどのように見えるかがわかります。

.container { 
 
    display: flex; 
 
    flex-flow: row wrap; 
 
    width: 40%; 
 
    margin-left: 30%; 
 
    margin-right: 30%; 
 
    padding-left: 0; 
 
    padding-right: 0; 
 
} 
 

 
#menu2 { 
 
    position: relative; 
 
    padding: 5% 0; 
 
} 
 

 
.mybox { 
 
     padding-top: 3%; 
 
     padding-bottom: 3%; 
 
     width: 30%; 
 
     font-size: 1.5em; 
 
} 
 

 
#mytextbox { 
 
     top: 30%; 
 
     z-index: 2; 
 
     order: 3; 
 
     border: 1px solid black; 
 
     background: 
 
      linear-gradient(
 
       rgba(255, 255, 255, 1), 
 
       rgba(255, 255, 255, 0.7) 
 
       ), 
 
       url('./../images/Pattern.png') bottom no-repeat; 
 
} 
 

 
#box1 { 
 
     position: absolute; 
 
     top: 5%; 
 
     order: 1; 
 
     background-color: rgb(66,142,158); 
 
     margin-right: 25%; 
 
     margin-left: -28%; 
 
} 
 

 
#box2 { 
 
     position: absolute; 
 
     order: 2; 
 
     background-color: rgb(196,52,52); 
 
     margin-left: 30%; 
 
     right: -28%; 
 
     top: 5%; 
 
} 
 
#box3 { 
 
     position: absolute; 
 
     order: 4; 
 
     background-color: rgb(223,187,66); 
 
     margin-right: 30%; 
 
     margin-left: -28%; 
 
     bottom: 5%; 
 

 
    } 
 
#box4 { 
 
     position: absolute; 
 
     order: 5; 
 
     background-color: rgb(80,139,97); 
 
     margin-left: 30%; 
 
     right: -28%; 
 
     bottom: 5%; 
 
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> 
 
<div id="menu2" class="container"> 
 
     <div id="mytextbox" class="col-sm-12 col-xs-12"> 
 

 
      <h2 id="h2Box1" style="visibility: visible">Text from the box1</h2> 
 
      <h2 id="h2Box2" style="visibility: hidden">Text from the box2</h2> 
 
      <h2 id="h2Box3" style="visibility: hidden">Text from the box3</h2> 
 
      <h2 id="h2Box4" style="visibility: hidden">Text from the box4</h2> 
 

 
      <p id="pBox1" style="visibility: visible">Paragraph from the box1</p> 
 
      <p id="pBox2" style="visibility: hidden">Paragraph from the box2</p> 
 
      <p id="pBox3" style="visibility: hidden">Paragraph from the box3</p> 
 
      <p id="pBox4" style="visibility: hidden">Paragraph from the box4</p> 
 

 
     </div> 
 
     <div id="box1" class="col-sm-6 col-xs-3 mybox active-box"> 
 
      <span class="hidden-xs">BOX NAME 1</span> 
 
      <span class="visible-xs">1</span> 
 
     </div> 
 

 
     <div id="box2" class="col-sm-6 col-xs-3 mybox"> 
 
      <span class="hidden-xs">BOX NAME 2</span> 
 
      <span class="visible-xs">2</span> 
 
     </div> 
 
     <div id="box3" class="col-sm-6 col-xs-3 mybox"> 
 
      <span class="hidden-xs">BOX NAME 3</span> 
 
      <span class="visible-xs">3</span> 
 
     </div> 
 
     <div id="box4" class="col-sm-6 col-xs-3 mybox"> 
 
      <span class="hidden-xs">BOX NAME 4</span> 
 
      <span class="visible-xs">4</span> 
 
     </div> 
 
    </div>

+0

ありがとう!これはまさに私が必要としていたものです。それはとてもシンプルでしたが、どういうわけか私はそれを見ていませんでした..あなたの助けに本当に感謝します! – marc08

+0

それはそれがうれしいです。 (y) 私はあなたの最初のイメージの>右サイドの要素の画面を調べました。 :D –

+0

ハハはそれが私の目の前にあったように見えます。ええ、このような素早い助けをありがとう!私は明らかにポジショニングについてもっと学ぶ必要があります。 – marc08

0

ここで行われているもの右は、あなたはそれが同じに見えるように接頭辞バージョンを使用しているので、これは、あなたが使用している箱が所定の高さと幅を有していることです他のデバイスでオーバーフロー:autoを置くと、基本的にdivより先にスペースを追加することができないため、余分なスペースが必要になることがdivに伝えられます。あなたがする必要があるのは、使用しているjavascript/cssを削除するか、大きなボックスに設定することです。これにはもっと大きなボックスが必要な場合に使用できるcol.sm.11があります。

+1

おい、時間ありがとう!ラハールの答えは私が探していたものでした。私は完全にあなたが意味するものを得る。しかし、この場合、「min-height」だけを使用するので、接頭辞のある高さはありません。だから、最小限の接頭辞が付きますが、私はそれが伸びると予想するより多くのコンテンツを追加します。位置を削除する:絶対に助けた。とにかくありがとうございました! – marc08

関連する問題