Since a span
is a inline
element, you can use text-align: center
to center the element within the column.
Example:
td{
width: 300px;
background-color: green;
text-align: center;
}
<table>
<tr>
<td><span>Esto es una prueba</span></td>
</tr>
</table>
As mentioned by @rnd, using the selector directly from the element will be changed for all the elements of that type that you have on your page. I simply put it as a quick example so you could see that it could be centered using the text-align: center
property. In case the table was static you could use a class.
As in your case, the table is created dynamically, you can refer to column 3 of each of the rows using the selector nth-child(3)
using tr > td:nth-child(3)
. This indicates that you take the td
element with the 3 position that is the son of a tr
.
Example:
td{
width: 100px;
background-color: green;
}
tr > td:nth-child(3){
text-align: center;
}
<table>
<tr>
<td><span>Esto es una prueba</span></td>
<td><span>Esto es una prueba</span></td>
<td><span>Esto es una prueba</span></td>
</tr>
<tr>
<td><span>Esto es una prueba</span></td>
<td><span>Esto es una prueba</span></td>
<td><span>Esto es una prueba</span></td>
</tr>
<tr>
<td><span>Esto es una prueba</span></td>
<td><span>Esto es una prueba</span></td>
<td><span>Esto es una prueba</span></td>
</tr>
</table>