Resolving gaps and spaces in table cells when using the HTML 5 doctype
Filed under: web development
comments (17) Views: 47,427
While building an HTML email for Goba (new site coming soon) I decided to use tables for layout rather than pure CSS; sadly the dizzying array of email clients make tables a far more reliable medium for this sort of thing. Into one cell I placed an image to be used as the top section of a rounded corner box. It looked great in every browser that I used to preview the email, but when I sent it out and checked it in GMail, there were mysterious spaces around each cell whose only contents were images. In my case, there were 4 of them.
After trying Firebug I turned to the internet where I learned that the HTML 5 doctype, used by Gmail, adds some mysterious spacing inside table cells when their only contents are inline elements. Turns out that the fix is to convert the inline element to a block level element with CSS. Here's an example with no doctype, and borders on the table turned on. To see the issue, remove the style attribute from the top and bottom image. Hope this helps someone else.
If this article was interesting, or helpful, or even wrong, please consider leaving a comment, or buying something from my wishlist. It's appreciated!