Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

resize the image to fit the dimensions of TD

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.

like image 797
Malloc Avatar asked Sep 20 '12 18:09

Malloc


People also ask

How do I change TD size in HTML?

To set the cell width and height, use the CSS style. The height and width attribute of the <td> cell isn't supported in HTML5. Use the CSS property width and height to set the width and height of the cell respectively. Just keep in mind, the usage of style attribute overrides any style set globally.

How do you fit a picture into a table cell?

The second is to click in each table, go to the Table Tools > Layout tab, click the AutoFit button, and choose Fixed Column Width. With those settings, you can drag a picture from Windows Explorer, or use the Insert > Picture dialog, to insert one picture into one cell.

How do I resize an image in HTML table?

Step 1: Firstly, we have to type the Html code in any text editor or open the existing Html file in the text editor in which we want to change the size of an image. Step 2: Now, place the cursor inside the img tag. And then, we have to use the height and width attribute of the img tag for changing the size of an image.


1 Answers

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;
}
like image 133
somdow Avatar answered Oct 06 '22 13:10

somdow