Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to center Font Awesome icons horizontally?

I have a table with a Font Awesome icon and I want to align text left and center icons. I tried with centering <i> but doesn't work:

HTML:

<td><i class="icon-ok"></i></td> 

CSS:

td, th {     text-align: left; } td i {     text-align:center; } 

jsFiddle

I also tried to set text-align:center !important; but doesn't work. What did I do wrong?

like image 999
Mustapha Aoussar Avatar asked Oct 03 '13 15:10

Mustapha Aoussar


People also ask

How do I align font awesome icons horizontally?

The most preferred way to center Font Awesome Icons is to assign a center class to each <i> tag. Setting width to 100%, let's each icon cover 100% area horizontally. Also text-align then centers the icon accordingly to the width being used.

How do I center font awesome icons vertically?

If you want to make a text appear vertically aligned next to a Font Awesome icon, you can use the CSS vertical-align property set to “middle” and also, specify the line-height property. Change the size of the icon with the font-size property.


2 Answers

Add your own flavour of the font awesome style

[class^="icon-"], [class*=" icon-"] {     display: inline-block;     width: 100%; } 

which along with your

td i {     text-align:center; } 

should center just the icons.

like image 193
andyb Avatar answered Sep 23 '22 16:09

andyb


Use text-align: center; on the block container of the icon (the <td>) - text-align doesn't apply to inline elements, only block containers:

td {     text-align: center; } 

http://jsfiddle.net/kB6Ju/2/

like image 31
Adrift Avatar answered Sep 19 '22 16:09

Adrift