tags:

views:

36

answers:

3

Hello!

I want to float a paragraph next to image, but without wrapping the image. Like this:

div.img {
        float: left;
        display: block;
        margin: 15px 2% 0 2%;
        width: 26%; /* I cannot use that */
}

div.info {
        float: right;
        display: block;
        margin: 15px 2% 0 2%;
        width: 66%; /* The width should be variable */
}

The problem is that I can do it if I set width to both img and info but the image is a variable width/height. It does not have specific width/height.

I am almost lost in this situation. Please suggest to me anything.I want both divs to float next to each other without wrapping .. without specifying box width.

Any solution..workaround?

A: 

Only float the image, not the paragraph of text:

img {
    float: left;
    margin-right: 10px;
}

p {
    font-family: Arial;
    font-size: 13px;
    line-height: 1.3em;
}

See: http://jsfiddle.net/9WMzZ/

Yi Jiang
Yes I did that, but the paragraph will wrap the image. which I want to avoid also.
Ahmad Fouad
@Ahmad - Ah silly me - I though wrap there meant something else. Okay, let me see if I can work something else out.
Yi Jiang
@Ahmad Does the outer box have a fixed height?
Yi Jiang
@Yi Jiang No. :) The content is dynamic, and the image(thumbnail) is set variable.. I think its not possible, I searched all the web for a solution for that .. I think i am forced to set width for each block :(
Ahmad Fouad
@Ahmad Well, if it's any help at all, here's a solution with a fixed parent height: http://jsfiddle.net/9WMzZ/1/
Yi Jiang
A: 
<div id="test">
    <img src="img.png"/><p>The problem is that I can do it if I set width to both img and info but the image is a variable width/height. It does not have specific width/height.<br/><br/>
ariable width/height. It does not have specific width/height.<br/><br/>ariable width/height. It does not have specific width/height.<br/><br/>ariable width/height. It does not have specific width/height.<br/><br/>ariable width/height. It does not have specific width/height.<br/><br/>ariable width/height. It does not have specific width/height.<br/><br/>ariable width/height. It does not have specific width/height.<br/><br/>ariable width/height. It does not have specific width/height.<br/><br/>ariable width/height. It does not have specific width/height.<br/><br/>
I am almost lost in this situation. Please suggest to me anything.I want both divs to float next to each other without wrapping .. without specifying box width.

Any solution..workaround?</p>
   </div>

Worked for me in FF with :

#test img, #test p{float:left; display:block}
Chouchenos
+1  A: 

You will need some js to do that: http://jsfiddle.net/vXMkR/ .

Adam
Not a bad solution, but quite fragile. I would probably drop a `onresize` event handler there just to be safe.
Yi Jiang