For example, I have a table which the first column has some elements with different length:
<table border="1" style="text-align:center;width:100%;">
<tr><td><span>a</span></td><td>1</td></tr>
<tr><td><span>a</span><span>a</span></td><td>1</td></tr>
<tr><td><span>a</span><span>a</span><span>a</span></td><td>1</td></tr>
<tr><td><span>a</span><span>a</span><span>a</span><span>a</span><td>1</td></tr>
<table>
How to add space to elements so that the elements in <td> is evenly distributed?
I tried:
span{
display:inline-block;
}
.container {
display: flex;
}
.container.space-around {
justify-content: space-around;
}
.spaceBetween{
display:space-between;
}
<table border="1" style="text-align:center;width:100%;">
<tr class="container space-around"><td class="spaceBetween"><span>a</span></td><td>1</td></tr>
<tr class="container space-around"><td class="spaceBetween"><span>a</span><span>a</span></td><td>1</td></tr>
<tr class="container space-around"><td class="spaceBetween"><span>a</span><span>a</span><span>a</span></td><td>1</td></tr>
<tr class="container space-around"><td class="spaceBetween"><span>a</span><span>a</span><span>a</span><span>a</span></td><td>1</td></tr>
</table>
but not working.
2
Answers
You just didn’t place your flex in the right place and were completely breaking the table. I’ve changed it so the flex is applied to the cell.
To evenly distribute the elements in the first column of a table, you can use CSS to apply a "text-align: justify" property to the cells in that column. Here’s an example of how you can achieve this:
By applying the "distribute" class to the cells in the first column (in this case, the elements), the "text-align: justify" property will evenly distribute the content in each cell. In this way, the elements will be spaced to fill the entire width of the column. Don’t forget to adjust the structure and content of the table to suit your specific needs.