2016-11-14 16 views
1

基本的なテキスト要素を含むdivを作成しようとしています。私の要件は、div内の要素はdivに従って整列する必要があります。したがって、私は相対的な位置にあるメインdivとの絶対的な位置付けを使用し、反応する画面で作業できるようにパーセンテージの値を与えました。私はメディアスクリーンのトップボトムのパーセンテージの一部を変更しました。ただし、画面サイズが変更された場合、テキストまたはdivの1ブロックが重複して表示されることがあります。応答画面でこの重複を避ける方法はありますか?事前にありがとう:)レスポンシブで絶対位置の重複を避ける

.Heading{ 
 
    position:relative; 
 
} 
 
.Heading h3{ 
 
    top:1%; 
 
    position:absolute; 
 
    left:0; 
 
    right:0; 
 
} 
 
.Text{ 
 
    Position: absolute; 
 
    top: 10%; 
 
} 
 
.bottom-part{ 
 
    position:absolute; 
 
    top:60%; 
 
}
<div class="main"> 
 
    <div class="Heading"> 
 
    <h3>Heading part</h3> 
 
    </div> 
 
    <div class="Text"> 
 
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It 
 
     has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop 
 
     publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p> 
 
    </div> 
 
    <div class="bottom-part"> 
 
    <h4>Here's the ending part</h4> 
 
    </div> 
 
</div>

+0

なぜこのdivを「絶対」にしたのですか?単にこのfloat:left'プロパティを実行することができます –

答えて

1

さて、私はあなたに簡単に、このようなmin-heightを設定することで、それを修正するための解決策を与えることができます:

.Heading { 
 
    position: relative; 
 
    min-height: 100px; 
 
} 
 
.Heading h3 { 
 
    top: 1%; 
 
    position: absolute; 
 
    left: 0; 
 
    right: 0; 
 
} 
 
.Text { 
 
    Position: absolute; 
 
    top: 10%; 
 
} 
 
.bottom-part { 
 
    position: absolute; 
 
    top: 60%; 
 
}
<div class="main"> 
 
    <div class="Heading"> 
 
    <h3>Heading part</h3> 
 
    </div> 
 
    <div class="Text"> 
 
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It 
 
     has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop 
 
     publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p> 
 
    </div> 
 
    <div class="bottom-part"> 
 
    <h4>Here's the ending part</h4> 
 
    </div> 
 
</div>

をしかし、あなたがやっていることはまったく正しいことではありません。この場合は、position: absoluteを決して使用しないでください。代わりに、この種のレイアウトには@mediaクエリを使用する必要があります。

+1

ありがとうございます。私はそれを試してみましょう。 – Harish

+0

@ハリッシュ確かに... ':)'私に知らせてください。 –

+1

ありがとうございます。絶対配置を完全に削除しました。私はメディアのクエリを使用して、いくつかの変更を加えました。 @Praveen Kumar – Harish