2

My icon is not centered to my input button, how do I get them aligned?

<span>
<i class="far fa-heart my-auto"></i>
<input type="submit" class="btn favorite-button bold-font py-0 px-1" name="favorite" value="Add to Favorites">
</span>

The icon does not have margin or padding so I cannot simply do a bootstrap "my-auto"

1 2

Button Press
  • 969
  • 3
  • 14

3 Answers3

1

You can use bootstrap 4.0 flex class to align item in the center

i {
  font-size: 20px;
  margin-right: 10px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/all.css" rel="stylesheet" />




<span class="d-flex align-items-center mt-2 ml-2">
                <i class="far fa-heart my-auto"></i>
                <input type="submit" class="btn favorite-button font-weight-bold py-0 px-1" name="favorite" value="Add to Favorites">
              </div>
Akbar Ali
  • 386
  • 1
  • 7
1

From the title i guess what you should try is to change the display to flex column and align the contents

<span class="d-flex flex-column justify-content-center align-items-center" style="width: 150px;">
        <i class="far fa-heart my-auto"></i>
        <input type="submit" class="btn favorite-button bold-font py-0 px-1" name="favorite" value="Add to Favorites">
</span>
1

just change your "far" class as below;

.far {
    font-family: 'Font Awesome 5 Free';
    font-weight: 400;
    padding: 5px;
    font-size: 1rem;
}
And Aydın
  • 84
  • 4