Home >Web Front-end >CSS Tutorial >How to Float an Image to the Left of Text Without Text Wrapping?
Question:
How do I float an image to the left of the text, ensuring the text does not wrap around the image?
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>
CSS Code:
.post-container { margin: 20px 20px 0 0; border: 5px solid #333; } .post-thumb img { float: left; clear:left; } .post-content { float:right; }
Solution:
To correct the placement and ensure the text does not wrap around the image:
1. Update the Overflow Property:
.post-container { ... overflow: auto; }
This will allow the text to flow alongside the image without wrapping.
2. Adjust the Margin-Left:
.post-content { ... margin-left: 210px; }
This will create a space between the image and the text, ensuring the text does not overlap.
3. Display the Image as a Block:
.post-thumb img { ... display: block; }
This will make the image behave like a block element, ensuring it stays in one line.
**4. Bolden and Enlarge the Post
The above is the detailed content of How to Float an Image to the Left of Text Without Text Wrapping?. For more information, please follow other related articles on the PHP Chinese website!