Consider the folloing 2-by-2 html table:
<table style="width: 100%; border-collapse: collapse; table-layout: fixed;">
<!-- First row -->
<tr>
<td style="padding: 0;">
<div style="width: 100%; height: 100%; border: 1px solid black; box-sizing: border-box;">
text
<br>
text
</div>
</td>
<td style="padding: 0;">
<div style="width: 100%; height: 100%; border: 1px solid black; box-sizing: border-box;">
text
</div>
</td>
</tr>
<!-- Second row -->
<tr>
<td style="padding: 0;">
<div style="width: 100%; height: 100%; border: 1px solid black; box-sizing: border-box;">
text
<br>
text
</div>
</td>
<td style="padding: 0;">
<div style="width: 100%; height: 100%; border: 1px solid black; box-sizing: border-box;">
text
</div>
</td>
</tr>
</table>
Each cell contains a div with borders. I want the divs to stretch to fill the entire cell so the div borders will touch each other. I have putted the height of all the divs to be 100%, but still on the second column they do not stretch up.
What should I do?
I asked this question chatgpt. he gave me planty of useless sujestions.
It is related There is also this question:
How do I stretch a div vertically in a td?
but the answr thier do not work in my case.
2
Answers
Give height: 100%; to table. This will possibly fix this issue.
What’s the idea behind using
div
s with borders inside table cells?If you need a regular table with borders on every side and between cells both horizontally and vertically, you can simply add borders to the table and to every cell. Applying
border-collapse: collapse;
on the table tag prevents the doubling of inner borders between cells.If there’s a good reason for specifically using
div
s in your case, describe it, and possibly I’ll be able to help with that.