Html – How to prevent 3px extra bottom padding on list items in IE7

csshtmlinternet-explorer-7layout

I have a page where the infamous 3px extra vertical space (below each li element) is being rendered in IE7 on all my list items. I have a specific situation where I need text absolutely positioned within the li, so that its container can be set to a smaller width, & the text extends beyond the container. Here's the code I'm using:

<style type="text/css">
 div { width: 160px; font: 8pt arial,helvetica,sans-serif; border: 1px solid #999; }
  div ul { margin: 0; padding: 0; list-style: none; }
   div ul li { width: 30px; height: 20px; margin: 0 0 4px; padding: 0; background-color: #c00; }
    div ul li a { display: block; line-height: 20px; color: #000; text-decoration: none; }
     div ul li a em { position: absolute; margin-left: 5px; }
</style>

<div>
 <ul>
  <li><a href="#"><em>#1: premature brake wear</em></a></li>
  <li><a href="#"><em>#2: squeaky brakes</em></a></li>
  <li><a href="#"><em>#3: bad gas mileage</em></a></li>
 </ul>
</div>

I'm looking for a solution that doesn't involve an IE7-specific CSS hack, just for CSS purity's sake. I've read that in a lot of cases, giving the containing elements hasLayout resolves most of these 3px extra height issues, but I haven't been able to figure it out for this code.

In my app, I ended up applying a different margin-bottom for IE7 (1px rather than 4px) which works fine but just doesn't seem right….

Test page here

Live app here

I've tried some of the standard fixes described on 456 Berea St & this page, but either I'm applying them incorrectly to my example, or it's something else in the way my code is structured. Any suggestions for fixes or other ways to accomplish this layout?

Best Answer

I haven't tried it with this code, but I've specified a height in the li elements, then added vertical-align: bottom, so the code would be:

div.test ul li { height: 20px; vertical-align: bottom;}

Works for me in both ie 6 & 7