My HTML code:
<div style="text-align:center;">
<table style="background-color:rgb(166, 235, 157); border: 2px solid black; width:100%;">
<tr>
<td style="border: 1px solid black;">
<img src="https://picsum.photos/200/300" width="100" height="150">
</td>
<td style="border: 1px solid black;">
<img src="https://picsum.photos/200/300" width="125" height="150">
</td>
<td style="border: 1px solid black;">
<img src="https://picsum.photos/200/300" width="150" height="150">
</td>
<td style="border: 1px solid black;">
<img src="https://picsum.photos/200/300" width="150" height="150">
</td>
<td style="border: 1px solid black; text-align:center">
<div style="width:100%; border:1px solid black; height:50px;"><img src="https://picsum.photos/200/300" width="150"></div>
<div style="background-color:rgb(148, 76, 17); width:100%; padding:5px; color: white; font-weight: bold; font-style: italic;">21 Apr, 2023</div>
<div style="background-color:rgb(20, 104, 104); padding:5px; color: white; font-style: italic; font-weight: bold;">Press Clippings</div>
<div style="width:100%; border:1px solid black; height:50px;"><img src="https://picsum.photos/200/300" width="150"></div>
</td>
</tr>
</table>
</div>
The output:
As you can see, the images are not properly fit into the table cells, I want the images to take 100% height of their parent table cells respectively, except for the 5th cell. How do I do it? Please guide me.
4
Answers
Define you width and height in CSS, not on the
<img>
tags themselves. I’ve set them to take up 100% of the space available to them, which seems to do what you want.I’ve made another version of the code with all your styles pulled out into separate CSS, it’s much more readable and manageable this way.
set
style="height:100%;"
for your images.You can define the images as background to the divs instead of adding as image tags, this will allow you to control them better with css: