How can I get Google Material Icons properly aligned in my Bootstrap buttons ?

For example, consider this code :

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">

<!-- body -->
<button type="button" class="btn btn-danger btn-sm">
  <span class="material-icons">delete</span> Supprimer
</button>

Gives me this output :

enter image description here

That is not very nice output. What is the best solution to fix the alignment between the icon and the text ?

3 Answers

2
bleuscyther On Best Solutions

Using Bootstrap class :

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">


<button type="button" class="btn btn-secondary d-flex justify-content-center align-content-between" (click)="refresh()" [disabled]="loading">
     <i class="material-icons mr-1">refresh</i> <span>Refresh</span>
 </button>

3
Andrew Bone On

You could do something like this (inline styles on the button)

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">

<!-- body -->
<button style="display: flex;align-items: center;padding:5px 10px;" type="button" class="btn btn-danger btn-sm">
  <span class="material-icons">delete</span> Supprimer
</button>

but I'd imagine there is a better way. This is just the first thing that springs to mind.

0
Manoj Kumar Sharma On

Try this. Hope this helps....

button i.material-icons {
    vertical-align: middle;
    padding-right: 10px;
    margin-right: 10px;
    border-right: 2px groove;
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">


<button type="submit" class="btn btn-primary">
    <i class="material-icons">delete</i>
    Delete Item
</button>