Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS Float: Floating an image to the left of the text

For each post box, I want the thumbnail to float to the left and the text to float to the right. I do not want the thumb to wrap around the text.

Here is my html code:

<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> 

I've tried a few ways and still can't get it to work... the text won't show on the right...

Here's my CSS code:

.post-container{     margin: 20px 20px 0 0;       border:5px solid #333; }  .post-thumb img {     float: left;     clear:left; }  .post-content {     float:right; } 
like image 416
Cris Avatar asked Mar 04 '11 19:03

Cris


People also ask

How do I float an image to the left?

To use a floating image in HTML, use the CSS property float. It allows you to float an image left or right. More property values include the following: Sr.No.

How do I put an image on the left side in CSS?

Float property in CSS will float an image to the left or right in the paragraph. The text in the paragraph will wrap around the image. Text-align property in CSS will position an image to the left, center or right of the page.

How do I float text next to an image in CSS?

Use the float CSS Property to Place the Text Next to an Image in HTML. We can use the float CSS property to define how an element can float. An element can float to the right or the left. Some other options are none which means the element will not float and, inherit which, will exhibit its parent's behavior.


1 Answers

Is this what you're after?

  • I changed your title into a h3 (header) tag, because it's a more semantic choice than using a div.

Live Demo #1
Live Demo #2 (with header at top, not sure if you wanted that)

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% } 
like image 104
thirtydot Avatar answered Sep 30 '22 12:09

thirtydot