ttmt — 2012-03-13T14:39:26-04:00 — #1
Gap on image bottom ?
I know it's another simple one but I can't work it out
I have a list of images here and they all seem to have a gap at the
bottom. What's causing the gap?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<style type="text/css" media="screen">
border: 1px solid red;
margin:0 0 10px 0;
<li><a href=""><img src="01.jpg" alt="" /></a></li>
<li><a href=""><img src="02.jpg" alt="" /></a></li>
<li><a href=""><img src="03.jpg" alt="" /></a></li>
<li><a href=""><img src="04.jpg" alt="" /></a></li>
</div><!-- #wrap -->
ralphm — 2012-03-13T17:11:50-04:00 — #2
I remember being really frustrated with this one. It's because, by default, images align themselves with the baseline of any text that might sit beside them, leaving room below for descenders like on the "p".
The easy way to fix it is to add the line in red to your style sheet:
border: 0 none;
<font color='"#FF0000"'>vertical-align: bottom;</font>
system — 2012-03-14T08:08:18-04:00 — #3
As Ralph suggested vertical-align:bottom fixes it -- but the core cause is that images are inline-level elements with a inline-block behavior by default. As such setting the img to be floated (as your massive gap on one side suggests there'll be other content next to them?) or setting them to display:block can also remove said gaps... and vertical-align doesn't always fix it in a reliable fashion.
Which is part of why I don't try to code layout until I have all the content in place -- so you don't add behaviors to an element without seeing how it interacts with everything else you're putting in there -- also the problem with snippets, we can't see the big picture.