The following webpage has a few pixels space between the image and the div. (I tested in Firefox 3 and Safari 4.)
How can I close the gap?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Test Page</title> <style type="text/css" media="screen"> body { background-color: black; } img { width: 250px; height: 70px; border: 0; margin: 0; padding: 0; } div { background-color: white; border: 0; margin: 0; padding: 0; } </style> </head> <body> <img alt="Qaru Logo" src="http://is.gd/lEfE"> <div>text</div> </body> </html>
The image is an inline element, so it is placed in the base line of the text string. The gap is the distance between the baseline and the bottom of the text line (Ie The space required below the baseline to suspend characters like "g" and "j").
Make the image a block element and the space will disappear:
display: block;
Remove the line break between the image tag and the div tag.
Add display: block to your <img> either in CSS or in the style attribute.
display: block
<img>
Change Guff beat me up.
You can also wrap <img> with <div> , which technically says in this case what you should do anyway. Only block-level elements can be descendants of <body> if I remember the HTML specifications correctly. Then you have the flexibility to add more images inside this div (if there is no free space between closing <img> and </div> ), you should be good to go.
<div>
<body>
</div>
Delete the new line in HTML between the <img> line and the <div> .
Why yes, it is annoying that HTML treats newlines as spaces.
Edit:
<img alt="Qaru Logo" src="http://is.gd/lEfE"> <div>text</div>
To:
<img alt="Qaru Logo" src="http://is.gd/lEfE"><div>text</div>
didn't work for me, but it does. Give it a negative field value - Valid CSS
img { width : 250px; height : 70px; border : 0; margin-top : -11px; margin-left : -22px; padding : 0; }
set up if necessary.