2
votes

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

enter image description here

as you can see, the fa icons is not at the center of text. How can i make the fa-icon in center ?

4
What happens instead of centering spans, you center divs?Jeredriq Demas
Put icons and text in a div then centering will work.Nathaniel Flick

4 Answers

4
votes

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>
3
votes

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>
2
votes

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>
-1
votes

Simply you can add one custom class for making those icons to center align.
You can check this fiddle.

.icon-center{
  margin:0 auto;
}