To organize all three table
's, place them within a single parent wrapper
and apply the CSS property display: flex;
. You can then use either justify-content: space-around;
or space-between
based on your preference to align them.
This setup arranges all tables in a row. You can specify a specific width
for each table using the calc
function to ensure they fit perfectly. Additionally, add a left and right margin
of 1em
to create appropriate spacing between the tables.
table
elements are not inherently responsive, so it's recommended to include media-queries
for different screen sizes. For instance, you can make the tables stack vertically on smaller screens by utilizing a media query with flex-direction: column;
.
table,
th,
td {
border: 1px solid black;
}
.wrapper {
display: flex;
justify-content: space-around;
}
table {
width: calc(100% / 3);
margin: 0 1em;
}
@media only screen and (max-width: 800px) {
.wrapper {
flex-direction: column;
}
table {
width: 100%;
margin: 1em 0;
}
<div class="wrapper">
<table>
<tr>
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
<tr>
<td>Alfreds Futterkiste</td>
<td>Maria Anders</td>
<td>Germany</td>
</tr>
<tr>
<td>Centro comercial Moctezuma</td>
<td>Francisco Chang</td>
<td>Mexico</td>
</tr>
</table>
<table>
<tr>
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
<tr>
<td>Alfreds Futterkiste</td>
<td>Maria Anders</td>
<td>Germany</td>
</tr>
<tr>
<td>Centro comercial Moctezuma</td>
<td>Francisco Chang</td>
<td>Mexico</td>
</tr>
</table>
<table>
<tr>
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
<tr>
<td>Alfreds Futterkiste</td>
<td>Maria Anders</td>
<td>Germany</td>
</tr>
<tr>
<td>Centro comercial Moctezuma</td>
<td>Francisco Chang</td>
<td>Mexico</td>
</tr>
</table>
</div>