Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Font Awesome icon alignment inside md-button

I'm trying to align font awesome icons inside a button so that they are centered in respect to text on a toolbar. I have the following markup;

<div ng-app="app">
  <md-toolbar>
      <div class="md-toolbar-tools" md-tall"">
        <h2>
          <span>Icons</span>
        </h2>
        <md-button class="md-icon-button">
          <md-icon md-font-icon="fa-circle" class="fa"></md-icon>
        </md-button>
        <md-button class="md-icon-button">
          <md-icon md-font-icon="fa-circle" class="fa fa-lg"></md-icon>
        </md-button>
    </div>
  </md-toolbar>
</div>

Which produces the following layout;

Mark above as rendered

fa-lg on the second icon makes it look centred although I suspect it is still aligned to the top. I tried sticking layout-alignment="center center" on the md-button to no effect.

How can I control the alignment of font awesome icons inside md-buttons and, specifically how can I vertically center these within the toolbar? Is there a Angular Material way of doing this alignment, or is custom CSS required here?

CodePen

like image 242
Stafford Williams Avatar asked Nov 27 '15 05:11

Stafford Williams


2 Answers

It appears to be the 24px fixed height on the md-icon element that is messing with icon's vertical alignment. The FontAwesome icon is designed with a dynamic height, so forcing a fixed height on the md-icon element isn't compatible; the middle of this element is no longer the middle of the icon. Try overriding this with height: auto; and it should work happily, e.g.:

md-icon {
  height: auto;
}
like image 150
t-jam Avatar answered Oct 26 '22 10:10

t-jam


The height added for md-icon is causing the issue

md-icon {    
    height: 24px;    
}

You need to add some extra class like follows

<md-icon md-font-icon="fa-circle" class="fa **fa-md**"></md-icon>

and need to override the height

.fa-md {
    height: auto;
}
like image 39
Shailesh Daund Avatar answered Oct 26 '22 10:10

Shailesh Daund