How can I center a <span class="glyphicon"></span>
within <td>
a table? It's a bit cumbersome to put them on theme...I'm using Laravel 5.2 and jquery's DataTable. It is a column that gives me values 1 or 0 and I, in my javascript, replace it with a glyphicon if it is a value of 1 or if it is a value of 0 to obtain the image that I am attaching. The issue is that I would like it to be centered (Active column):
Since a
span
is an elementinline
, you can usetext-align: center
to center the element within the column.Example:
As @rnd has told you, using the selector directly from the element will change it for all elements of that type you have on your page. I just gave it as a quick example so you could see that it could be centered using the
text-align: center
. In case the table was static you could use a class.Since in your case the table is created dynamically, you can refer to column 3 of each of the rows via the selector
nth-child(3)
usingtr > td:nth-child(3)
. This tells it to take the elementtd
with position 3 that is a child of atr
.Example:
When you create the table use the option
columns
to be able to add a class to alltd
of a specific column withclassName
. Datatables comes with classes to align cells, if you are using their styles you can use the classdt-center
or use the bootstrap class:text-center
:Since you're using Bootstrap, you don't need to add any additional CSS.
Add the class
.text-center
to the container, as in the second row of this example.Salu2