CSS - table and image height issue

Hi

I have a table, and one of the columns displays a preview to a document. The preview is about 1000px in height, but I want the row to be limited to 100px in height, and the user can scroll to see the rest of the preview, or just click on the link to open the document in Word Online.

With the samples below, the row height keeps adjusting to fit the whole image.

Any help is greatly appreciated.

Here is a link to my sample on w3schools

Here is the HTML I am using:
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
    border: 1px solid black;
}

ex1 {
    max-height: 50px;
    overflow: auto;
}
</style>
</head>
<body>

<table>
  <tr>
    <th>Month</th>
    <th>Savings</th>
  </tr>
  <tr >
    <td class="ex1"><img src="https://www.clicktorelease.com/tmp/google-svg/image.svg" height="250px"/></td>
    <td >$100</td>
  </tr>
  <tr>
    <td>February</td>
    <td>$80</td>
  </tr>
</table>


</body>
</html>

Open in new window

maaknplanAsked:
Who is Participating?
 
Jan LouwerensConnect With a Mentor Software EngineerCommented:
Try adding a div to the table cell, and style on that:

    <td class="ex1"><div><img src="https://www.clicktorelease.com/tmp/google-svg/image.svg" height="250px"/></div></td>

Open in new window


.ex1 div {
    max-height: 50px;
    overflow: auto;
}

Open in new window


https://www.w3schools.com/code/tryit.asp?filename=FP838PTRTCJV
0
 
maaknplanAuthor Commented:
Thanks Jan, your solution works great.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.