Forum Moderators: not2easy

Message Too Old, No Replies

IE6 + 7: Floated image gets unwanted bottom margin

         

badtant

2:32 pm on Nov 6, 2008 (gmt 0)

10+ Year Member



Hi,

I have a div with some text inside. Inside the same div I have an image that is floated to the right so that the text wraps around it. Everything works just fine except for in IE6 where the image gets an unwanted margin under itself.
There shouldn't be any space between the border of the image and the border of the parent div.

Can't find any solution for this... do you have one? Here's the code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title></title>
<style type="text/css">
/* RESET AND MAIN STYLING */
blockquote,body,caption,div,dl,dt,dd,form,fieldset,h1,h2,h3,h4,h5,h6,html,li,ul,ol,p,pre,textarea,table,td,th {
margin:0;
padding:0;
}

body {
font:0.6875em/1.5em verdana,sans-serif; /* 11 px */
background:#e2e2e2;
color:#000000;
}

input,select,textarea,button{
font-size:100%;
font-family:verdana,sans-serif;
}

p,ul,ol,dl,blockquote,form,fieldset {
margin:1em 0;
}

img {
border:0;
display:block;
}

/* COMMON CLASSES */
.clearfix:after {
display:block;
visibility:hidden;
clear:both;
height:0;
content:".";
}

.clearfix {
display:inline-block;
}

.clearfix {
display:block;
}
</style>
</head>
<body>
<div class="clearfix" style="border:1px solid #000;">
<img src="http://www.example.com/badtant/test/pic_butterfly.jpg" alt="" style="float:right;border:1px solid #000;" />

<h1>Utvecklingsprocessen</h1>

<p>Hur går det till när en idé blir ett projekt som sen kanske blir en del av vår verksamhet? Här kan du översiktsversionen av utvecklingsprocessen. Här kan du titta på den fullständiga versionen.</p>

</div>
</body>
</html>

[edited by: badtant at 3:04 pm (utc) on Nov. 6, 2008]

[edited by: swa66 at 8:40 pm (utc) on Nov. 6, 2008]
[edit reason] no URLS please, use example.com, see forum charter [/edit]

swa66

3:02 pm on Nov 6, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'd suggest to make a small test case that shows the problem and post some code illustrating the problem.

On that note: inline images go on the text baseline, that might be your problem.

badtant

3:06 pm on Nov 6, 2008 (gmt 0)

10+ Year Member



Code is now posted! Copy and paste to a html document.

swa66

4:50 am on Nov 7, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your problem isn't there in the standards compliant browsers such as FF3, safari and opera. IE 6 and IE7 show it both.

I don't typically use strict xhtml myself (I do need iframes for advertising, so I can't). Hence I don't know how to work around the IE problems in this case.

alt131

1:20 pm on Nov 7, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi badtant!

On the provided code the issue can only be seen if the image has a height taller than the total height of the paragraph. (Best practise is to always give images a height and width.)

If that is when the issues arises, remove the unwanted space below the image in ie6&7 by removing the bottom margin applied to the <p>aragraph.

(On a side note, if the multiple rules for div.clearfix are to force the div to expand to contain the image, another option is to remove all the existing rules and just use

display:inline-block
)

badtant

1:47 pm on Nov 7, 2008 (gmt 0)

10+ Year Member



swa66: Yes, only IE6 and 7

alt131:
Yes, that is when the problem occurs. Setting a height and width on the image doesn't solve anything. display:inline-block instead of clearfix doesn't change anything either.

Removing the bottom margin applied to the <p>aragraph does work. I'm not quite happy with the solution though. I need that margin so it would be great with another solution that doesn't interfere with my <p>aragraphs.

alt131

3:04 pm on Nov 7, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi badtant,

Per my post, removing the margin from the <p>aragraph fixes the stated issue. Feel free to ask for more information if you are not sure why I made the other suggestions.

I'm not quite happy with the solution though. I need that margin so it would be great with another solution that doesn't interfere with my <p>aragraphs.

Unfortunately I'm not sure what you mean by "interference" and why you "have" to use margin.

When I tested your code before posting the fix for the stated question,

padding
(or
padding-bottom
) created a visual space after the <p>ara without triggering a space on the bottom of the image. However, if that is not an option, perhaps provide more information about what you are trying to achieve.

mercedes

8:39 am on Nov 8, 2008 (gmt 0)

10+ Year Member



apply "vertical-align: top;" to floated img element. that may solve your problem.

badtant

8:39 am on Nov 10, 2008 (gmt 0)

10+ Year Member



alt131:
Well, I don't have to, but I want to use margins. I think margin is the right thing to use instead of padding. I just don't want this bug to change how i write code. Best solution so far that I've found is to apply a minus bottom margin to floated images.

mercedes:
Didn't work. Would have been great if id did :)