简体   繁体   中英

How to style mat-card-title inside mat-card

I wanted to truncate mat card title for overflow. Using

overflow:hidden 
text-overflow:ellipsis
white-space: nowrap

But the style is overriden by the standard mat-card style. I used mat-card-header ::ng-deep for the same but I think ng-deep is deprecated now. Does anyone know of a better approach for the same?

=> Instead of using the ng deep , you can override the class css .

=> go to the main css file common/ style .css inspect your material class from browser like

. "use the full class name which you found from browser" {

// apply the css

}

=> save and run .

This might help:

<mat-card class="example-card">
    <mat-card-header>
    <mat-icon>more_vert</mat-icon>
        <div mat-card-avatar class="example-header-image"></div>
        <mat-card-title title="This is a test title header">This is a test title header</mat-card-title>
        <mat-card-subtitle>Dog Breed</mat-card-subtitle>
    </mat-card-header>
</mat-card>

and you can override the css class in your component ie your component is (app.component.css):

.mat-card-title {
  overflow:hidden ;
  text-overflow:ellipsis;
  white-space: nowrap;
  width: 30vw;
}

You must need to specify width for text overflow ellipsis, Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM