I am stuck on something where I have many pages of content with a message field. In this message box, you can have images, text, headers, etc. However, each message window will have an icon in the upper right corner of the window. The image will sit at the top of the window if I use the position: absolute. However, if the message field has a heading or paragraph and is filled with the width of the field. The text will sit under the image.
I basically need a wrapper around the image with a width, so the text will only sit to the edge of the image. I'm 99% sure that this works for me in firebug, wrapping the absolute positional image in a div and giving it some styles. But I canβt get it to work today!
There are hundreds of pages, so moving HTML around is not an option. There is currently no wrapper in the image. So I need to use jQuery to wrap the image. (If this is the answer).
I know that an absolute position takes an element outside the document stream, but is there something I can do?
Anyway, here is my code:
<div class="message"> <h3>Some text, a header perhaps? But this is the next that will sit under the image, sometimes it ap tag.</h3> <img class="messageIcon" src="/link-to-icon/which-are-the-same-size" border="0" width="64" > <p>Some more random text that would appear in the messagebox this could go on for a few lines.</p> </div> <script type="text/javascript"> $(document).ready(function(){ $('img.messageIcon').wrap('<div class="messageIconWrap" />'); alert("this is a test"); }); </script>
JS wraps div around image
CSS
.messageIconWrap{ display: inline-block; float:right; height:60px; width:60px; } div.message { position: relative; } .message { background: none repeat scroll 0 0 #393939; clear: both; } .messageIcon { position: absolute; right: 20px; top: 20px; float: right; }
JS Fiddle - http://jsfiddle.net/jdp7E/
source share