Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular Material: How to use `mat-icon` as `mat-card-avatar` within `mat-card-header`?

Providing an image avatar within a mat-card-header is well supported via mat-card-avatar.

enter image description here

There are many use-cases where we'd like to use an icon, instead of an image, as the card's "avatar".

Is there an easy way to replace the avatar with an icon?

This below sort of works, but is not quite as nice as the avatar image.

enter image description here

like image 362
conner.xyz Avatar asked Nov 11 '19 19:11

conner.xyz


People also ask

How do I display two mat cards on the same row?

Try adding display: inline-block !

When can I use mat card?

The <mat-card> is a container for the content that can be used to insert the media, text & action in context to the single subject. The basic requirement for design the card is only an <mat-card> element that has some content in it, that will be used to build simple cards.


1 Answers

The mat-card-avatar directive can be applied to any element including <mat-icon>. You will need to apply style to the icon to get the size right:

<mat-card>
  <mat-card-header>
    <mat-icon mat-card-avatar>home</mat-icon>
    ...

mat-icon.mat-card-avatar {
  width: 40px;
  height: 40px;
  font-size: 40px;
}
like image 188
G. Tranter Avatar answered Nov 11 '22 21:11

G. Tranter