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
Release: 2024-11-11 12:52:02
Original
1008 people have browsed it

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>
Copy after login

CSS Code:

.post-container {
    margin: 20px 20px 0 0;  
    border: 5px solid #333;
}

.post-thumb img {
    float: left;
    clear:left;
}

.post-content {
    float:right;
}
Copy after login

Solution:

To correct the placement and ensure the text does not wrap around the image:

1. Update the Overflow Property:

.post-container {
    ...
    overflow: auto;
}
Copy after login

This will allow the text to flow alongside the image without wrapping.

2. Adjust the Margin-Left:

.post-content {
    ...
    margin-left: 210px;
}
Copy after login

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;
}
Copy after login

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!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template