Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Font Awesome with Bootstrap 4

A Major problem I found while developing with Bootstrap 4 and trying to create a Font Awesome button that when I create a series of buttons, I get different size buttons, the only way to get the same size buttons is to use the same font for each one So the problem is due to Font Awesome sizes is not the same for every one.

      <a class="btn btn-outline-warning" type="button" href="#">
        <i class="fa fa-edit"></i>
      </a>

      <a class="btn btn-outline-danger" type="button" href="#">
        <i class="fa fa-trash"></i>
      </a>

Does one have a practical exemple to get Off this problem ?

like image 592
Med Karim Garali Avatar asked May 01 '18 15:05

Med Karim Garali


People also ask

How to add Font-Awesome icons in Bootstrap 4 forms?

For single-input forms in bootstrap 4, a nice way to place font-awesome icons is the input-group-addon class: &lt;div class="input-group"&gt; &lt;span class="input-group-addon"&gt; &lt;i Stack Overflow About Products For Teams Stack OverflowPublic questions & answers

What is the best icon library for Bootstrap 4?

Bootstrap 4 does not have its own icon library ( Glyphicons from Bootstrap 3 are not supported in BS4). However, there are many free icon libraries to choose from, such as Font Awesome and Google Material Design Icons.

How do I add icons to Bootstrap 4?

Bootstrap 4 Icons. Bootstrap 4 does not have its own icon library (Glyphicons from Bootstrap 3 are not supported in BS4). However, there are many free icon libraries to choose from, such as Font Awesome and Google Material Design Icons. To use Font Awesome icons, add the following to your HTML page (No downloading or installation is required):

Do I need to download or install Font Awesome?

Note: No downloading or installation is required! You place Font Awesome icons by using the prefix fa and the icon's name.


1 Answers

While you can certainly manually adjust the font size of your Font Awesome icons, I would suggest a less dramatic approach: .fa-fw. This is a utility class that is part of Font Awesome's stylesheet that helps unify the width of your fonts. Per the 4.7.0 documentation:

Use fa-fw to set icons at a fixed width. Great to use when different icon widths throw off alignment. Especially useful in things like nav lists & list groups.

<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet">
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" type="text/css" rel="stylesheet">

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js"></script>
<script type="text/javascript" src="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>

<a class="btn btn-outline-warning" href="#">
  <i class="fa fa-fw fa-edit"></i>
</a>

<br>

<a class="btn btn-outline-danger" href="#">
  <i class="fa fa-fw fa-trash"></i>
</a>

<br>

<a class="btn btn-outline-success" href="#">
  <i class="fa fa-fw fa-wrench"></i>
</a>

<br>

<a class="btn btn-outline-info" href="#">
  <i class="fa fa-fw fa-stop"></i>
</a>

In the above example you can see how .fa-fw has adjusted your icon spacing and everything looks the same. You might notice though that I did also remove type="button" from your anchor tag as this was resulting in Bootstrap not applying the full CSS of the ban-outline-* you were declaring.

like image 185
Robert Avatar answered Oct 25 '22 06:10

Robert