I'm currently working on aligning a table by centering the td elements and left justifying the text inside them.
My initial attempt was to use flex for center alignment, which worked to some extent but I couldn't get the left alignment right.
I came across a solution that involved using padding-left: 50%
, but it didn't meet my requirements.
table {
color: #212121;
font-size: .875rem;
margin: 1.25rem 0;
border-collapse: collapse;
table-layout: fixed;
width: 100%;
border: 1px solid red;
}
tr {
display:flex;
width: 100%;
justify-content: center;
}
tr td {
max-width: 50%;
text-align:left;
border: 1px solid blue;
}
<table>
<tbody>
<tr>
<td>lorem ipsum</td>
<td>alpha</td>
</tr>
<tr>
<td>lorem ipsum ipsum</td>
<td>teata ipsum alpha</td>
</tr>
</tbody>
</table>
What I aim to achieve:
The borders are included purely for reference in terms of spacing.