views:

101

answers:

1

Hi all, I've just encountered a problem that my current (almost equal to 0) CSS knowledge cannot deal with. Here's the thing:

I have some text inside of a div element; this div element (let's call it a container) has a fixed width and dynamic height (no constraints). I'd like to put some text inside of the container; after the second word of the text, I'd like to put an image so that the whole things looks more or less like that:

+---------------------+
| I was [x] on my way |
| to the city in the  |
| sun                 |
+---------------------+

where [x] is the image. It's important for the second part of the text to wrap so that everything looks like in the above example.

The text in the container may vary; nevertheless I always know which part of the text goes before and which part of the text goes after the image.

How do I do that with CSS?

+2  A: 

If you put the <img> tag in the middle of your text, things should behave like that by default, unless you override the image's display property. You may also want to experiment with the image's vertical-align property to make it line up nicely with the surrounding text.

tdammers
Thanks for answering! Will it work with image that comes from a sprite?
Karol
Not sure what you mean by "sprite". Any kind of image supported by the target browser will work - jpeg and gif are widely supported, and most browsers also accept png. Other image types are platform- and browser-dependent.
tdammers
I was thinking of a sprite like that: http://css-tricks.com/css-sprites/ . I'm not using explicit images, but div's with appropriate background setting.
Karol
I see. In that case, you'd have to explicitly set `display: inline-block` on the image div to make it behave as intended. This works on all standards-compliant browsers, but I think IE6 and maybe even 7 does not understand `inline-block`. `display: inline` probably won't work, because it doesn't give you enough control over the element's height.
tdammers
Thanks a lot! You're right, display: inline-block helped. Unfortunately, it needs a hack to work for IE7- (http://www.brunildo.org/test/inline-block.html) but the solution you provided is exactly what I needed.
Karol