2017-07-11 4 views
1

私はプロジェクトに取り組んでいます。さまざまな方法で、使用しているプラ​​ットフォームの画像の横に注意深くテキストを置くことができました。画像とテキストの両方が中央揃えされていますが、テキストは左詰めです。浮動小数点の中心にあるアイテムを保持する問題

ページは応答性が高く、一般的にうまくいくはずですが、ブラウザのサイズが縮小するにつれて、最終的にテキストは次の行にプッシュされます。残念なことに、これが起こると、もはや中心合わせされなくなり、画像は中心からずれる。

私は、現在のテーマ/ユースケース内で何が修正できるかを正確に把握しようとしばらく頑張ってきました。 https://jsfiddle.net/xLwy83rj/

<div style="width: 50%; margin: 0 auto; min-width: 250px;"> 
<!--I edit the margins in the next block to better prevent the text from flowing over the bottom of the image if its a smaller or larger block of text --> 
<img style="float: left; margin-right: 1rem; margin-top: 15px; margin-bottom: 15px;" src="http://via.placeholder.com/128x128" /> 
</div> 

<div style="display: inline-block; width: 200px;"> 
<p style="text-align: left;"><strong>Attack Gloves</strong><br /> 
Base DPS: ~<strong>572.5</strong><br /> 
Attack Range: <strong>1100</strong><br /> 
Heat Buildup: <strong>95</strong><br /> 
Heat Buildup: <strong>95</strong><br /> 
Heat Buildup: <strong>95</strong><br /> 
Heat Buildup: <strong>95</strong></p> 

は、具体的な目標は、それらの間のスペースを少しだけで、すべての時間を中心に2つの主要な要素を維持することです。ブラウザが小さすぎて横並びに表示できない場合は、テキストを下に押し下げて、すべてを中央に維持します。

+0

少し変更を作成してくださいことはできますか? –

+0

でフィドルを

+0

@RobertWilliamsthe jsfiddleが投稿されました。 – NRGdallas

答えて

1

demo used flex

.main { 
 
    display: flex; 
 
    justify-content: center; 
 
    flex-wrap: wrap; 
 
} 
 

 
.p{ 
 
    margin: 0; 
 
}
<div class="main"> 
 
<div class="top"> 
 
<img class="alignnone second" src="http://via.placeholder.com/128x128" /> 
 
</div> 
 

 
<div class="third"> 
 
    <p class="p"><strong>Attack Gloves</strong><br /> 
 
    Base DPS: ~<strong>572.5</strong><br /> 
 
    Attack Range: <strong>1100</strong><br /> 
 
    Heat Buildup: <strong>95</strong><br /> 
 
    Heat Buildup: <strong>95</strong><br /> 
 
    Heat Buildup: <strong>95</strong><br /> 
 
    Heat Buildup: <strong>95</strong></p> 
 
</div> 
 
</div>

+0

閉じるが、コンテンツはラップした後に真ん中に座っています。折り返しの後、テキストはイメージの下に座りますが、上記の行にテキストがないという事実のために位置を再調整しません。 編集:それは価値がありますが、これは私が得た最も近いものです。これまでのショットの中で最も近いものです! – NRGdallas

+1

フレックスを使用した最新の反復が機能するようになりました!ありがとう、ありがとうございました、そして、私はこれについてもっと詳しく読むようになっていますので、将来私はそれをもっとよく理解することができます!再度、感謝します! – NRGdallas

0

このHTMLを試してみてください

HTML

<div style="text-align:center;width:50%;margin:auto;"> 
<!--I edit the margins in the next block to better prevent the text from flowing over the bottom of the image if its a smaller or larger block of text --> 
<img class="alignnone" src="http://via.placeholder.com/128x128" style="display:inline-block;" /> 
<p style="display:inline-block;"><strong>Attack Gloves</strong><br /> 
Base DPS: ~<strong>572.5</strong><br /> 
Attack Range: <strong>1100</strong><br /> 
Heat Buildup: <strong>95</strong><br /> 
Heat Buildup: <strong>95</strong><br /> 
Heat Buildup: <strong>95</strong><br /> 
Heat Buildup: <strong>95</strong></p> 
</div> 

Link for reference

あなたはすべての時間を中心とし続けるしたい項目https://jsfiddle.net/
+0

十分なスペースがない場合を除いて、テキストは画像の下に置かれます。また、一度折り返すと、テキストのdiv/blockではなく、各行のテキストが中央に配置されます(これは実際問題の巨大な部分ではありません)。 – NRGdallas

+0

メインのdivの幅を削除して試してみてください –

+0

まだ垂直に座っています - 視覚的プレビューでは実際にはそれが横並びに表示され、それは実際にはより小さなウィンドウです - 私は何らかの理由が出てくるかどうかを見るために今遊んでいます>> – NRGdallas

0

<div style="width: 50%; margin: 0 auto; min-width: 250px; text-align:center; float:left;"> 
 
<!--I edit the margins in the next block to better prevent the text from flowing over the bottom of the image if its a smaller or larger block of text --> 
 
<img class="alignnone" style="display:inline-blcok; margin-right: 1rem; margin-top: 15px; margin-bottom: 15px;" src="http://via.placeholder.com/128x128" /> 
 

 
</div> 
 
<div style="display: inline-block; width: 200px; float:left;"> 
 
<p style="text-align: left;"><strong>Attack Gloves</strong><br /> 
 
Base DPS: ~<strong>572.5</strong><br /> 
 
Attack Range: <strong>1100</strong><br /> 
 
Heat Buildup: <strong>95</strong><br /> 
 
Heat Buildup: <strong>95</strong><br /> 
 
Heat Buildup: <strong>95</strong><br /> 
 
Heat Buildup: <strong>95</strong></p> 
 

 
</div>

+0

この画像では、テキストはそこにない限り、テキストの横にそれを保持することが目的です。さらに、テキストは折り返しの後に整列されます – NRGdallas

+0

これを処理するために、適切なクラスとメディアクエリを異なるスクリーンサイズで使用する必要があります。クラスで適切なコードを作成し、異なる画面サイズで処理するCSSのメディアクエリを記述してください。 –