Three tables were created with identical column names. The HTML markup for each table is consistent. When viewed on a laptop browser, the tables display correctly as depicted in this screenshot:
https://i.sstatic.net/5BAdg.png
However, when viewed on a smaller screen (mobile device), the widths of the tables are distorted:
https://i.sstatic.net/8coWv.png
The issue arises because the second and third tables have longer column names compared to the first table. How can I ensure that all tables have the same width when viewed on a mobile phone? What CSS code do I need to achieve this? Thank you in advance for your help.
The code snippet is provided below:
table {
border-collapse: collapse;
border-spacing: 0;
width: 100%;
border: 1px solid #ddd;
}
th,
td {
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #f2f2f2
}
<div style="overflow-x:auto;"> <table> <tr> <th style="width: 15%">First Name</th> <th style="width: 15%">Last Name</th> <th style="width: 7%">Points</th> ...