I am trying to align a table, center(the td) and left the text inside td;
I try to use flex to align center, which in a way it does, but can't align left.
I've seen the solution which uses padding-left: 50%, but that doesn't fit my needs.
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 want to obtain:
The border line, are just for distance comparison

you can insert span tag in table,html code:
<table>
<tbody>
<tr>
<td><span>lorem ipsum</span></td>
<td><span>alpha</span></td>
</tr>
<tr>
<td><span>lorem ipsum ipsum</span></td>
<td><span>teata ipsum alpha
teata ipsum alpha</span></td>
</tr>
</tbody>
</table>
css code:
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;
justify-content: center;
text-align:center;
}
tr td{
border: 1px solid blue;
width:50%;
}
tr td span{
display:inline-block;
width:50%;
text-align:left;
white-space:break;
}
this result's link: https://jsbin.com/huvitefeqe/edit?html,css,js,output
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With