Currently, I am developing a web application with Google Script that generates a dashboard featuring multiple tables. To design the layout, I am utilizing Bootstrap (https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css). Despite my extensive search efforts, I have been unable to pinpoint the missing element in my code.
Specifically, within one of the tables, I am trying to insert an image that should be horizontally and vertically centered in the middle of the td cell. Moreover, it must adapt to the height of the row or td that I choose.
Unfortunately, my image consistently ends up at the bottom of the td/row, often overlapping and extending beyond the row. Although the image appears to have the correct height, its positioning is incorrect. To clarify, I have included a snippet of my code:
Here is the output I am currently getting
Below is the relevant section of my code:
.row {}
table {
text-align: center;
}
tr {
line-height: 20px;
}
th,
td {
position: relative;
text-align: center;
vertical-align: middle;
}
img {
display: block;
vertical-align: center;
position: absolute;
height: 20px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<base target="_top">
<meta charset="utf-8>
<meta name="viewport" content="width=device-width, initial-scale=1>
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fb9994948f888f899a8bbbced5cad5c8">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous>
<?!= include("page-css"); ?>
</head>
<body>
<div class="container">
<div class="row" style="width: 500px">
<!-- TABLE TEST -->
<div>
<table class="table">
<thead>
<tr>
<th>Rank</th>
<th>Name</th>
<th>Points</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td><img src="https://static.sky.it/images/skytg24/it/spettacolo/serie-tv/2021/02/25/spongebob-serie-tv-kamp-koral/kamp.jpg"></td>
<td>3</td>
</tr>
<tr>
<td>11</td>
<td><img src="https://static.sky.it/images/skytg24/it/spettacolo/serie-tv/2021/02/25/spongebob-serie-tv-kamp-koral/kamp.jpg"></td>
<td>33</td>
</tr>
<tr>
<td>111</td>
<td><img src="https://static.sky.it/images/skytg24/it/spettacolo/serie-tv/2021/02/25/spongebob-serie-tv-kamp-koral/kamp.jpg"></td>
<td>333</td>
</tr>
</tbody>
</table>
</div>
<!-- CLOSE TABLE TEST -->
I have experimented with various solutions I discovered, including display: block, position: relative for parents, position: absolute for children, and several other techniques. However, none of these approaches have yielded the desired results. It is evident that I am overlooking a crucial detail, and my numerous styling modifications may be obscuring the correct solution. Any assistance in resolving this issue would be greatly appreciated.
Thank you to anyone who can provide guidance.