I'm currently using FontAwesome, and am having a really hard time centering the icons both vertically and horizontally in their container. I have tried doing it via positioning and ran into issues bc the icon sizes were different. I basically have the horizontal, and am trying to get the vertical.
<div class='container'> <div class='row'> <div class='offset2 span6 loginContainer'> <div class='row'> <div class='login-icon'> <i class='icon-user'></i> </div> <input type="text" placeholder="Email" /> </div> <div class='row'> <div class='login-icon'><i class=" icon-lock "></i></div> <input type="password" class="" placeholder="Password" /> </div> </div> </div> </div> .login-icon{ font-size: 40px; line-height: 40px; background-color:black; color:white; width: 50px; height: 50px; } .login-icon [class*='icon-']{ height: 50px; width: 50px; display: inline-block; text-align: center; vertical-align: baseline; }
http://jsfiddle.net/ncapito/e2UPC/
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.
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.
To pull icon fa-align-right to the right of the container use fa-pull-right class.
This is all you need, no wrapper needed:
.login-icon{ display:inline-block; font-size: 40px; line-height: 50px; background-color:black; color:white; width: 50px; height: 50px; text-align: center; vertical-align: bottom; }
http://jsfiddle.net/e2UPC/6/
I have used transform to correct the offset. It works great with round icons like the life ring.
<span class="fa fa-life-ring"></span> .fa { transform: translateY(-4%); }
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