I created a skinny
CSS class that has no margin, padding or border:
.skinny
{
margin:0 0 0 0;
padding:0 0 0 0;
border:0 0 0 0;
}
And I applied it to a row containing an image which also has the skinny
class applied to it:
<td width="33%" align="center" class="skinny">
<table width="400px" height="180px" class="skinny">
<tr class="skinny">
<td class="skinny" width="60px" height="100px"><a class="skinny" href="/"><img class="skinny" width="60px" height="100px" id="snapshot" src="/images/snapshot.png"></a></td>
<td class="skinny" width="120px" height="100px"><a class="skinny" href="/"><h1 class="skinny">Product</h1></a></td>
</tr>
</table>
</td>
I'm trying to get the image to appear as close as possible to the <h1>
text in the next cell so that they are pushed up against each other, left-to-right.
But no matter how many elements I apply the skinny
class to, there seems to be something like a 'padding' around each of the table cells that creates a space between the image and the text.
How do I remove that?
Related. HTML tables are comprised of rows and cells. In traditional HTML coding you remove the spacing within a cell by setting the “cellspacing” attribute to zero.
To remove this space we can use the CSS border-collapsing Property. This Property is used to set the borders of the cell present inside the table and tells whether these cells will share a common border or not.
To set cell padding in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <table> tag, with the CSS property padding.
Images are inline elements and sit on the base line, they are treated just like a letter with no descender (i.e. like a, b and c but not g, j and y).
Set the image to display: block
to avoid this (or twiddle with vertical-align
)
Better yet, since it looks like you have a 1x2 table: don't use tables for layout
the table itself also give padding. so the table definition needs to be
<table width="400px" height="180px" class="skinny" cellspacing="0" cellpadding="0">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With