Forum Moderators: not2easy
when I take margin-left away the space under the images goes away again.
#footer{
background: red;
}
#img2{
margin-left: 10px;
}
img{
border: 0;
}
<div id="footer">
<img src="image1.gif" alt="1" /><a href="#" id="img2" ><img src="image2.gif" alt="2" /></a>
</div>
(xhtml transitional)
if you know how to fix this, please reply. It's really doing my head in.
[edited by: encyclo at 2:32 pm (utc) on Oct. 5, 2007]
[edit reason] no screenshot links please [/edit]
You could try setting vertical-align on your img:
img{
border: 0;
vertical-align:bottom;
} Does that have any effect?!
to be complete here is the entire code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>test margin</title>
<style type="text/css">
#footer{
background: red;
}
#img2{
margin-left: 10px;
}
img{
border: 0;
}
</style>
</head>
<body>
<div id="footer">
<img src="image1.gif" alt="1" /><a href="#" id="img2" ><img src="image2.gif" alt="2" /></a>
</div>
</body>
</html>
I'm not sure, however, why the margin-left property should cause this in FF. And I'm not sure why FF should do this with a Transitional DOCTYPE (I thought it was only in full standards(Strict) mode). But, the 'bottom margin' effect shows in IE6 as well, regardless of whether margin-left is set. You will only see the 'bottom margin' in Opera with a Strict DOCTYPE.
Just to expand on what I said above, images are inline elements and in standards compliant browsers they should sit on the text baseline - not the bottom of the containing line box. The gap you see beneath the image is not a margin, but the space allowed for any descenders on surrounding(imaginary) text. Another way round this is to set display:block on the img element, but then you'd need to start floating your img's as well.
its not just in FF. also IE7.
"The gap you see beneath the image is not a margin, but the space allowed for any descenders on surrounding(imaginary) text."
yes, but when you take 'margin-left' away its just images next to eachother, no space above or below, like it should in the document flow. I just realy want to know how this margin-left can cause that space.
OK, I did the option with floating the images left. Only works when the container has overflow: hidden. but thats ok.
Still think its wierd margin-left has that effect.
Thanks for replies.