2017-12-20 8 views
0

セクションの高さが700pxです。このセクションの内側にはコンテナがあります。これは、コンテナ内の内容が高さが700pxを超えており、オーバーフローが表示され、これが目的の効果です。ただし、このセクションの下に別のセクションを追加すると、新しいセクションの内容がオーバーフローしたコンテナの一部と重なって表示されます。高さが設定されたセクションでオーバーフローを表示する方法はありますか?

<section class="info"> 
    <div class="container"> 
     <!--Some Content--> 
    </div> 
</section> 
<section class="text"> 
    <!--Some Content--> 
</section> 

私はコンテナクラス1のzインデックスを与えてみましたし、また情報セクションにあふれ見えると1のzインデックスを与えるが、何も動いていないようにみえました。

Codepen:https://codepen.io/KevinM818/pen/EoybqZ

+1

我々は問題を再現できるように、実際の作業のデモを投稿する必要があります。 –

+0

https://codepen.io/KevinM818/pen/EoybqZ –

+0

ちょうどそれのcodepenを作った –

答えて

2

z屈折率は、absolutefixed、又はrelativeように配置されている要素上で動作します。ライトブルーボックスを抽出してposition: absolute;に設定し、 divとcontainer divの両方にz-indexを設定します。または、z-index: -1;" to the bg div and removeポジションand z-インデックスfrom theコンテナdivに設定することができます。

調整

* { 
 
    padding: 0; 
 
    margin: 0; 
 
} 
 

 
.info { 
 
    height: auto; 
 
    position: relative; 
 
} 
 

 
.bg { 
 
    height: 700px; 
 
    background: lightblue; 
 
    position: absolute; 
 
    top: 0; 
 
    left: 0; 
 
    width: 100%; 
 
    z-index: 0; 
 
} 
 

 
.info .container { 
 
    position: relative; 
 
    width: 100px; 
 
    height: 750px; 
 
    margin: 0 auto; 
 
    background: grey; 
 
    z-index: 1; 
 
} 
 

 
.text { 
 
    height: 500px; 
 
    background: green; 
 
}
<section class="info"> 
 
    <div class="bg"></div> 
 
    <div class="container"> 
 
    <!--Some Content--> 
 
    </div> 
 
</section> 
 
<section class="text"> 
 
    <!--Some Content--> 
 
    <h1>How do I stop this green from overlapping the grey container?</h1> 
 
</section>

: 私は他の記事にコメントを見ました。緑色のボックスに灰色のボックスが重なるようにするには、元のコードのをinfo divに追加するだけです。

* { 
 
    padding: 0; 
 
    margin: 0; 
 
} 
 

 
.info { 
 
    position: relative; 
 
} 
 

 
.info { 
 
    height: 700px; 
 
    background: lightblue; 
 
    position: relative; 
 
} 
 

 
.info .container { 
 
    width: 100px; 
 
    height: 750px; 
 
    margin: 0 auto; 
 
    background: grey; 
 
} 
 

 
.text { 
 
    height: 500px; 
 
    background: green; 
 
}
<section class="info"> 
 
    <div class="container"> 
 
    <!--Some Content--> 
 
    </div> 
 
</section> 
 
<section class="text"> 
 
    <!--Some Content--> 
 
    <h1>How do I stop this green from overlapping the grey container?</h1> 
 
</section>

+0

@Kevin Mangal緑色のボックスに灰色のボックスが重なり合うようにするには、2番目のコードスニペットを追加しました。 – brian17han

0

あなたが緑のテキストを対象とする場合は、その後、あなたはsection.info700pxよりも背が高くできるようにする必要があります。

は、top=700pxsection.text絶対位置を与えるsection.infoheight制約を削除し、それをz-index高を与え、それがうまくいかなければなりません。 codepen調整

https://codepen.io/anon/pen/BJzJzE

+0

デザインの目的は、コンテナを次のセクションにオーバーラップさせることです。 section.infoの高さの制約を取り除くと、コンテナの高さに自動的にフィットします。 –

+0

投稿したコードペンを見てください。私はこれがあなたが「次のセクションに重なっている」(つまり緑色のテキストが灰色で覆われている)ことを意味していると仮定しています。私は両方のセクションを浮かべて、それらに絶対的な位置付けを与えました。それがあなたが意味することではない場合、おそらく私は要件を正しく理解していないでしょうか? – dragfyre

関連する問題