How do I force an image to fill its table cell COMPLETELY

荒凉一梦 提交于 2021-01-27 04:27:49

问题


I have read through many forums and tried the solution there but none of them have worked I still have a small gap between all my images. Here is the code:

<table id="Table">
            <tr>
                <td id="td1"><h2>~ Curling ~</h2></td>
                <td id="td2" rowspan="2"><img src="../images/curlingMid.jpg" 
                width="100%" height="100%" border="2" alt=""/></td>
                <td id="td1"><h2>~ Curling ~</h2></td>
            </tr>
</table>


#td1 { width: 32%;vertical-align: text-top; }
#td2 { padding-right: 5px; padding-top: 5px; }

回答1:


The image is an inline element and has some white space below it because of how it is aligned with the baseline.

To fix it, try:

#td2 img {display: block;}

or

#td2 img {vertical-align: bottom;}

Fiddle demo: http://jsfiddle.net/audetwebdesign/WxrvC/

Note that you have set 5px padding to the top and right of the image, and I assumed that is for styling purposes.

Also, id attributes should be unique on a page, use class, much easier to maintain and allows for easier re-use of CSS rules.




回答2:


different browsers render html elements with different default padding/margins/spacing etc.. you can try reset these like this:

#table td {padding: 0px; margin: 0px;}
#table {border-spacing: 0px;}


来源:https://stackoverflow.com/questions/16841455/how-do-i-force-an-image-to-fill-its-table-cell-completely

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!