resize the image to fit the dimensions of TD
Asked Answered
P

3

16

This table has 2 columns and 5 rows; in each cell I put an image and I need that image to fit the td dimensions.

Here is my HTML and CSS code:

#menu{
        float:right;
        width:200px;
        height:650px;
        border-bottom:none;
        border-left:solid 1px;

}


#menu img{
        width:100%; height:auto;;
}

td{
  border:solid 1px;
}

<table id="menu" cellspacing="0">
<tr><td class="item"><img src="../mke.jpg"/></td><td class="item"><img src="../mke.jpg"/></td></tr>
<tr><td class="item"><img src="../mke.jpg"/></td><td class="item"><img src="../mke.jpg"/></td></tr>
<tr><td class="item"><img src="../mke.jpg"/></td><td class="item"><img src="../mke.jpg"/></td></tr>
<tr><td class="item"><img src="../mke.jpg"/></td><td class="item"><img src="../mke.jpg"/></td></tr>
</table>

What I got is this:

enter image description here

The images doesn't fit all the cells.

How can I re-size these images? I need a suggestion which works with IE9.

Peele answered 20/9, 2012 at 18:14 Comment(0)
M
42

Just make the images width to 100% and make the height auto to keep the images from looking distorted

so something like

#menu img{
      display:block; width:100%; height:auto;
}
Milkmaid answered 20/9, 2012 at 18:27 Comment(2)
How to make sure image always matches the height of the cell as well?Hawaiian
This worked for me! I did not need to use the display:blockClemenceau
H
3

If you want it to fit exactly, use width:100% and height:100%.

The properties max-width and max-height do not set the dimensions of an element, they restrict the dimensions.

Hemo answered 20/9, 2012 at 18:18 Comment(0)
D
0

Font Size & display block

<td style="font-size:0px">
   <img src="IMG_URL" width="XXX" style="display:block;"> 
</td>
Daggna answered 14/2, 2021 at 18:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.