'centering text below font awesome icon
Good day, I'm using Font-awesome and bootstrap 4. Please check my Script first
<div class="container">
<div class="row">
<div class="col">
<div class="row">
<span class="fa fa-building fa-5x text-center"> </span>
</div>
<div class="row">
<h3 class="text-center">Company Profile</h3>
</div>
</div>
<div class="col">
<div class="row">
<span class="fa fa-shopping-cart fa-5x text-center"> </span>
</div>
<div class="row">
<h3 class="text-center">Shopping Cart</h3>
</div>
</div>
<div class="col">
<div class="row">
<span class="fa fa-industry fa-5x text-center"> </span>
</div>
<div class="row">
<h3 class="text-center">Inventory Control</h3>
</div>
</div>
<div class="col">
<div class="row">
<span class="fa fa-users fa-5x text-center"> </span>
</div>
<div class="row">
<h3 class="text-center">User Management</h3>
</div>
</div>
</div>
</div>
with my script above i get this
as you can see, the fa icons is not at the center of text. How can i make the fa-icon in center ?
Solution 1:[1]
Add the text-center class to the div surrounding your icon instead of of the icon span like so:
<div class="row text-center">
<span class="fa fa-users fa-5x"> </span>
</div>
Solution 2:[2]
You can simplify your HTML markup to the below and the text under icons will be center aligned based on the class text-center assigned to parent col div.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<div class="container">
<div class="row">
<div class="col-md-3 text-center">
<span class="fa fa-building fa-5x"> </span>
<h3>Company Profile</h3>
</div>
<div class="col-md-3 text-center">
<span class="fa fa-shopping-cart fa-5x"> </span>
<h3>Shopping Cart</h3>
</div>
<div class="col-md-3 text-center">
<span class="fa fa-industry fa-5x"> </span>
<h3>Inventory Control</h3>
</div>
<div class="col-md-3 text-center">
<span class="fa fa-users fa-5x"> </span>
<h3>User Management</h3>
</div>
</div>
</div>
Solution 3:[3]
Simply add the "text-center" class to the "fa" element container:
from:
<div class="row">
<span class="fa fa-building fa-5x text-center"> </span>
to:
<div class="row text-center">
<span class="fa fa-building fa-5x text-center"> </span>
Solution 4:[4]
Simply you can add one custom class for making those icons to center align.
You can check this fiddle.
.icon-center{
margin:0 auto;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Phani Kumar M |
| Solution 3 | Berckoff |
| Solution 4 | ilmk |

