2016-06-23 4 views
0

画像の下に2つの異なる段落がある画像が1つあります。正しい場所に保管してください。画像がどのように見えるかSee jsfiddle here to get a clearer idea「トップ」CSS属性を使用してテキストに画像が挿入されないようにする

私がコードを実装した方法に直面している問題は、画面が小さくなると、左のテキストが画像を押し上げるということです。誰も私がこれを防ぐ方法を知っていますか?

jsfiddleで画面を小さくすると、左側のテキストが画像に表示されます。それがために、次の行である:

.left { 
    position: relative; 
    top: -100px; 
} 

多分それは私が異なる画面サイズのメディアクエリを記述維持する必要がある場合がありますか?うまくいけばそれだけではないが、これは私が考えることができる唯一の解決策である。

下記の完全なコードを参照してください。

*, 
 
*:after, 
 
*:before { 
 
    -webkit-box-sizing: border-box; 
 
    -moz-box-sizing: border-box; 
 
    box-sizing: border-box; 
 
} 
 

 
[class*='col-'] { 
 
    float: left; 
 
} 
 

 
.col-1-2 { 
 
    width: 50%; 
 
} 
 

 
.grid:after { 
 
    content: ""; 
 
    display: table; 
 
    clear: both; 
 
} 
 

 
[class*='col-'] { 
 
    padding-right: 20px; 
 
} 
 

 
[class*='col-']:last-of-type { 
 
    padding-right: 0; 
 
} 
 

 
.left { 
 
    position: relative; 
 
    top: -100px; 
 
} 
 

 
img { 
 
    width: calc(100% - 1.2em); 
 
    display: block; 
 
} 
 

 
.img-wrap { 
 
    display: inline-block; 
 
    position: relative; 
 
    width: 100%; 
 
}
<div class="img-wrap"> 
 
    <img class="section-img" src="http://i.stack.imgur.com/LcAqZ.jpg"> 
 
</div> 
 

 
<div class="bottom-section"> 
 
    <div class="grid"> 
 
    <div class="left col-1-2"> 
 
     <h3>Test</h3> 
 
     <p>Test test</p> 
 
    </div> 
 
    <div class="col-1-2"> 
 
     <h3>Test</h3> 
 
     <p>Test</p> 
 
    </div> 
 
    </div>

+0

これは正常な動作が期待されています...あなたはいつもそれが通常より100pxに高いように.left' 'でそのテキストを明示的に語っています。これは、スクリーンが特定のサイズである場合にのみ良好に見えます。あなたはどのように見えますか? – Joseph

+0

@Joseph私はそれが画面のサイズが小さくなるにつれて画像の「左手側」の下の一定点にとどまりたい –

答えて

0

これは、この方法ではこれが許容できる方法で実行可能ではないと思います。背景はイメージの一部なので、イメージのサイズが変更され、テキストがイメージ内にスライドして表示されます。

私の推薦は、2枚の画像をカットし、次の構造を作成するには、次のとおりです。

  • 比較的配置のdiv
  • 内側全部が二つにあなたの画像を分割して、列にそれらを配置入れ。
  • ラッパーのdivに配置したテキストを、あなたの列に.img-wrapのdiv
  • 使用ポジショニングとマージンと一緒にテキストがVSを作成し、列
  • 内の要素を揃えるための場所
  • それらの上に簡単な制御を持っているので、 CSS付きバッジ

これは非常におおまかに行われた例であることに注意してください(私はこれをまとめる方法を示すためにいくつかの生成された画像を使用しています)。また、一部の測位値が完全に正確でない場合もあります。これはちょうどあなたのアイデアを示すことです。

*, 
 
*:after, 
 
*:before { 
 
    -webkit-box-sizing: border-box; 
 
    -moz-box-sizing: border-box; 
 
    box-sizing: border-box; 
 
} 
 

 
[class*='col-'] { 
 
    float: left; 
 
} 
 

 
.col-1-2 { 
 
    width: 50%; 
 
} 
 

 
.grid:after { 
 
    content: ""; 
 
    display: table; 
 
    clear: both; 
 
} 
 

 
[class*='col-'] { 
 
    padding-right: 20px; 
 
} 
 

 
[class*='col-']:last-of-type { 
 
    padding-right: 0; 
 
} 
 

 
.details { 
 
    height: 50px; 
 
} 
 

 
.right .details{ 
 
    position: absolute; 
 
    bottom: -50px; 
 
} 
 

 
.right .img-wrap { 
 
    margin-top: 50px; 
 
} 
 

 
img { 
 
    width: calc(100% - 1.2em); 
 
    display: block; 
 
} 
 

 
.img-wrap { 
 
    display: inline-block; 
 
    position: relative; 
 
    width: 100%; 
 
} 
 

 
.item { 
 
\t position: relative; 
 
} 
 

 
.vs { 
 
    position: absolute; 
 
    top: calc(50% - 25px); 
 
    left: calc(50% - 25px - 0.3em); 
 
    background-color: #fff; 
 
    width: 50px; 
 
    height:50px; 
 
    line-height: 50px; 
 
    text-align: center; 
 
    font-size: 30px; 
 
    border-radius: 25px; 
 
}
<div class="item"> 
 
<div class="img-wrap"> 
 
    <div class="grid"> 
 
    <div class="col-1-2"> 
 
     <div class="img-wrap"> 
 
     <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs=" class="img-wrap" /> 
 
     </div> 
 
     <div class="details"> 
 
     <h3>Test</h3> 
 
     <p>Test test</p> 
 
     </div> 
 
    </div> 
 
    <div class="col-1-2 right"> 
 
     <div class="details"> 
 
     <h3>Test</h3> 
 
     <p>Test</p> 
 
     </div> 
 
     <div class="img-wrap"> 
 
     <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs=" class="img-wrap" /> 
 
     </div> 
 
    </div> 
 
    </div> 
 
    <div class="vs">VS</div> 
 
</div>

0

ため、私はあなたのhtmlコードのあなたの質問のためのメディアクエリを使用していました。

*, 
 
*:after, 
 
*:before { 
 
    -webkit-box-sizing: border-box; 
 
    -moz-box-sizing: border-box; 
 
    box-sizing: border-box; 
 
} 
 

 
[class*='col-'] { 
 
    float: left; 
 
} 
 

 
.col-1-2 { 
 
    width: 50%; 
 
} 
 

 
.grid:after { 
 
    content: ""; 
 
    display: table; 
 
    clear: both; 
 
} 
 

 
[class*='col-'] { 
 
    padding-right: 20px; 
 
} 
 

 
[class*='col-']:last-of-type { 
 
    padding-right: 0; 
 
} 
 

 
.left { 
 
    position: relative; 
 
    top: -100px; 
 
} 
 

 
img { 
 
    width: calc(100% - 1.2em); 
 
    display: block; 
 
} 
 

 
.img-wrap { 
 
    display: inline-block; 
 
    position: relative; 
 
    width: 100%; 
 
} 
 

 
@media only screen and (max-width: 768px) { 
 
    .left{ 
 
    top:-85px; 
 
    } 
 
} 
 
@media only screen and (max-width: 480px) { 
 
    .left{ 
 
    top:-65px; 
 
    } 
 
    @media only screen and (max-width: 320px) { 
 
    .left{ 
 
    top:-52px; 
 
    }
<div class="img-wrap"> 
 
    <img class="section-img" src="http://i.stack.imgur.com/LcAqZ.jpg"> 
 
</div> 
 

 
<div class="bottom-section"> 
 
    <div class="grid"> 
 
    <div class="left col-1-2"> 
 
     <h3>Test</h3> 
 
     <p>Test test</p> 
 
    </div> 
 
    <div class="col-1-2"> 
 
     <h3>Test</h3> 
 
     <p>Test</p> 
 
    </div> 
 
    </div>

0

私はあなたが達成したいものを与え、異なっこれに近づくでしょう。イメージを2つの列に分割し、右側の列(イメージとテキスト)を少し下に置くだけでオフラインにすることができます。 Hereは例です。

別の方法としては、置くために次のようになります。

.left{ 
    top: 10vw; 
} 

または応答する同様の値。 10vwは常にビューポート幅の10%に等しいので、画面が小さくなるとオフセットも小さくなります。

0

問題は、画面サイズに比例して画像を拡大/縮小することですが、100pxオフセットは比例して拡大/縮小されません。画像が縮小するにつれて、下の空白もサイズを変更します。

コンテナの高さに関連するスケーリングアイテムは、通常、軽度の痛みであり、HTMLの大幅な再構築が必要になります。それはあなたが2枚の画像を分割する必要がありhttps://jsfiddle.net/pdkb1Lf5/14/

.versus { 
    display: block; 
    position: absolute; bottom:50%; left:50%; margin-left:-45px; 
    width: 90px; height:90px; line-height:90px; 
    background:#fff; border-radius: 50%; 
    text-align:center; 
    font-family:sans-serif; font-size:40px; text-transform:uppercase; 
} 

:ここ

は代替バージョンです。この方法は非常に難しいでしょうが、それはスケールの失敗を "対"グラフィックに渡すことに気付きます。これははるかに安全です。

また、ie8を無視することが許可されている場合は、VHユニットを試すことができます。

関連する問題