Cover Image for How to Wrap Text around an image in Html
74 views

How to Wrap Text around an image in Html

To wrap text around an image in HTML, you can use the CSS float property along with appropriate positioning. Here’s an example:

HTML
<!DOCTYPE html>
<html>
  <head>
    <style>
      /* CSS styles for the image and text */
      .image {
        float: left;
        margin-right: 10px;
      }
  
      .content {
        overflow: hidden; /* Ensures the content clears the floated image */
      }
    </style>
  </head>
  <body>
    <!-- Your HTML content goes here -->
  
    <div class="content">
      <img src="your-image.jpg" alt="Image" class="image">
      <p>
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque aliquam nunc eget quam dapibus, sed convallis nisi interdum. Duis luctus ex eget purus lacinia, sit amet pulvinar risus malesuada. Aenean dictum lacus eu arcu tempus vestibulum.
      </p>
    </div>
  </body>
</html>

In the example above, we wrap text around an image by floating the image to the left using the CSS float: left; property. The margin-right property adds some spacing between the image and the text. The .content class ensures that the text clears the floated image by setting overflow: hidden;.

You can adjust the CSS styles as per your specific requirements. Additionally, make sure to replace "your-image.jpg" with the actual path to your image file.

Remember to consider responsive design and the impact of floated elements on the layout, especially on smaller screens.

YOU MAY ALSO LIKE...

The Tech Thunder

The Tech Thunder

The Tech Thunder


COMMENTS