Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

float:right and relative positioning

This seems like it should be a simple solution, but I can't seem to figure it out.

I need to position an image in the same spot on every page. And I need the text to wrap around both the top and bottom of the image.

http://jsfiddle.net/4AnsK/

Notice the space for the image at the top-right? It doesn't shift down with the image. I understand why this happens, but I can't figure out how to make it work.

I've tried using relative positioning and setting the "top" value. I've tried margin-top, padding-top, putting it in an absolute div container, etc. I can't seem to figure it out. Any help is appreciated.

like image 300
Jason Thuli Avatar asked Jan 16 '23 15:01

Jason Thuli


1 Answers

This seems to work, but it needs a bit of a HTML hack. Basically, you just need to put a zero-width spacer above the image to push it down without affecting anything else.

Add this to the HTML, before the image:

<span id="evilNonSemanticSpacer"></span>

And use this CSS:

#evilNonSemanticSpacer {
    float:right;
    display:block;
    height:210px;
}
img
{
    float: right;
    clear:right;
}​

Remove the relative positioning from the image and it is in the right place with the text wrapping around it. The example fiddle is here.

There is an oddity with Chrome's text wrapping (the line above sits over the image). It doesn't appear in Firefox, though. The only way I can fix it in Chrome is with margin-top: 1.1em on the img, but that'll also result in white space above the image in Firefox (and possibly other browsers).

like image 144
IBBoard Avatar answered Jan 29 '23 03:01

IBBoard