I have a table in which some rows contain text and other rows contain images (inside a td with a colspan).
The problem is that if the image is larger than the width of the other rows(with text), it changes the size of the table. I actually want the image to shrink to the width of the table that is already there without having to give a specific pixel value.
table {
display: inline-table;
/* border-collapse: collapse; */
border-spacing: 0.1rem 1rem;
}
td {
border: 2px solid rgb(0, 140, 255);
padding: 0.2rem 2rem;
border-radius: 1em;
margin-top: 20px;
text-align: center;
}
.answer-button {
cursor: pointer;
padding: 0.2rem 1.8rem;
}
<table>
<tr>
<td class="year edge-left">1</td>
<td class="year edge-right">O1</td>
<td class="answer-button incorrect edge-left">A</td>
<td class="answer-button correct">B</td>
<td class="answer-button incorrect">C</td>
<td class="answer-button incorrect edge-right">D</td>
</tr>
<tr>
<td colspan="6"><img src="https://images.unsplash.com/photo-1494253109108-2e30c049369b?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&w=1000&q=80"></td>
</tr>
<tr>
<td class="year edge-left">2</td>
<td class="year edge-right">B1</td>
<td class="answer-button correct edge-left">A</td>
<td class="answer-button incorrect">B</td>
<td class="answer-button incorrect">C</td>
<td class="answer-button incorrect edge-right">D</td>
</tr>
</table>
The width of the table in the second image is the same as that of a table without that image. And I want the image to shrink to that width, instead of the image changing the width of the table.
The dimensions of the screenshots are nearly same in both, you can see the difference in the width of the table. I achieved the screenshot for the second image by setting a fixed pixel value for the image, but I don't think that would be a good solution.