Home >Web Front-end >CSS Tutorial >How to Float an Image to the Left of Text Without Text Wrapping?

How to Float an Image to the Left of Text Without Text Wrapping?

DDD
DDDOriginal
2024-11-11 12:52:02967browse

How to Float an Image to the Left of Text Without Text Wrapping?

CSS Float: Floating an Image to the Left of the Text

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn