問題
画像をフローティングするのが困難ですHTML 要素内のテキストの左側に配置されますが、テキストは右側に保持され、画像がテキストの周囲に回り込むのを防ぎます。
現在の実装
HTML コードは次のとおりです。 :
<div class="post-container"> <div class="post-thumb"><img src="thumb.jpg" /></div> <div class="post-title">Post title</div> <div class="post-content"><p>post description description description etc etc etc</p></div> </div>
CSS コード:
.post-container{ margin: 20px 20px 0 0; border:5px solid #333; } .post-thumb img { float: left; clear:left; } .post-content { float:right; }
解決策
望ましい結果を達成するには、次の変更を加えることができます。
HTML:
<div class="post-container"> <div class="post-thumb"><img src="http://dummyimage.com/200x200/f0f/fff" /></div> <div class="post-content"> <h3 class="post-title">Post title</h3> <p>post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc post desc </p> </div> </div>
CSS:
.post-container { margin: 20px 20px 0 0; border: 5px solid #333; overflow: auto } .post-thumb { float: left } .post-thumb img { display: block } .post-content { margin-left: 210px } .post-title { font-weight: bold; font-size: 200% }
説明
以上がCSS で画像をテキストの左側にフロートさせるにはどうすればよいですか?の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。