Professional Documents
Culture Documents
HTML - Table TD Leaves Unwanted Space at The Bottom - Stack Overflow
HTML - Table TD Leaves Unwanted Space at The Bottom - Stack Overflow
2024 Developer survey is here and we would like to hear from you! Take the 2024 Developer Survey
2 <table>
<tr>
<td>
<div class="container">
<img src="http://.../baking-potato.jpg" />
</div>
</td>
</tr>
</table>
The td cell is not wrapping "perfectly" the div+img content: as you can see from this fiddle,
there's a margin in the bottom of the cell, highlighted by the black background.
How can I get rid of that unwanted margin? I tried the following css properties
table{
border-spacing: 0 px;
border-collapse: collapse;
}
possible duplicate of Remove spacing between table cells and rows – Pbk1303 Dec 3, 2013 at 10:13
https://stackoverflow.com/questions/20348085/table-td-leaves-unwanted-space-at-the-bottom?rq=3 1/3
6/11/24, 6:40 PM html - table td leaves unwanted space at the bottom - Stack Overflow
Reason:
This happens because an <img> is an inline element, and therefore leaves space for text
characters like p and y for example, because it is inheriting the line-height
Share Improve this answer Follow edited Dec 3, 2013 at 10:16 answered Dec 3, 2013 at 10:10
Nick R
7,754 2 23 32
1 That's the original JSFiddle. I think you need to click Update. – ADTC Dec 3, 2013 at 10:15
Not sure why this occours here. I have tried several things. The following CSS seems to work for
me:
0
.container img {
margin-bottom: -5px;
}
However it's a hack and therefor not a really good practise in my opinion. But sometimes you just
don't get around using hacks...
not a really good practise in my opinion . There you go, might be worth reading up on this :)
– Nick R Dec 3, 2013 at 10:17
https://stackoverflow.com/questions/20348085/table-td-leaves-unwanted-space-at-the-bottom?rq=3 2/3
6/11/24, 6:40 PM html - table td leaves unwanted space at the bottom - Stack Overflow
Not really related to this case, but for someone having issue with <pre> wrapperd in <td> , you
may need to set margin: 0 to remove the space. This is the case I met with when using
0 codeblock in hugo.
Share Improve this answer Follow answered May 17, 2019 at 16:43
mach6
370 6 6
https://stackoverflow.com/questions/20348085/table-td-leaves-unwanted-space-at-the-bottom?rq=3 3/3