In a set of HTML pages containing some important text that requires a background color. This can happen anywhere on the page.
I also have an image that should float right on every page. The text should wrap around this image.
Sometimes text that requires a background color must wrap a floating image.
The problem is that the background color of the text extends below the image. Like this:

Here is the html and CSS:
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Float Problem</title> <style type="text/css"> .main{ width:500px; } .floater { height:200px; width:200px; background-color:#C00; float:right; clear:left; margin:10px; padding:10px; overflow:hidden; } .importantText { background-color:#333; color:#FFF; padding:5px; font-weight:bold; } </style> </head> <body> <div class="main"> <div class="floater"> [An image here] </div> <p class="plainText">Integer luctus, nunc vel condimentum ornare, mi eros vehicula nisl, non adipiscing enim risus sit amet urna. </p> <p class="importantText">In hac habitasse platea dictumst. Fusce nec felis lorem. Fusce mollis ante elit, at tempor ipsum. Ut imperdiet libero sed sem rutrum rhoncus mattis erat aliquam. Aenean bibendum tincidunt erat sit amet varius. Vivamus sed arcu vitae magna aliquet porttitor quis sed augue. </p> <p class="plainText">Fusce molestie dignissim libero vehicula egestas. Suspendisse porta, felis et auctor suscipit, quam mi facilisis odio, id tempus lorem leo ac quam. Proin rhoncus dignissim eros, et commodo ante rhoncus sit amet.</p> </div> </body> </html>
I tried many different proposed solutions, but none of them found a job for this particular problem. Is there a way to make the background color match the text (rather than go under the image)? Can this be solved using CSS or JavaScript (with access to jQuery)? The solution should work in IE7 +, FF4 +, Safari3 + and the latest Chrome.
source share