简体   繁体   中英

changing font on pre-built angular material theme

is it possible to change the font of a prebuilt angular material theme, eg the deeppurple-amber.css?

I only ever find examples of creating custom themes where you have to define pretty much everything yourself. I am really only interested in setting my own font.

Please find below code to change default font

@import "~@ng-select/ng-select/themes/material.theme.css";

@import '~@angular/material/theming';

// Define a custom typography config that overrides the font-family as well as the
// `headlines` and `body-1` levels.
    $custom-typography: mat-typography-config(
    $font-family:   'Roboto',
    $display-4:     mat-typography-level(112px, 112px, 300),
    $display-3:     mat-typography-level(56px, 56px, 400),
    $display-2:     mat-typography-level(45px, 48px, 400),
    $display-1:     mat-typography-level(34px, 40px, 400),
    $headline:      mat-typography-level(24px, 32px, 400),
    $title:         mat-typography-level(20px, 32px, 500),
    $subheading-2:  mat-typography-level(16px, 28px, 400),
    $subheading-1:  mat-typography-level(15px, 24px, 400),
    $body-2:        mat-typography-level(14px, 24px, 500),
    $body-1:        mat-typography-level(14px, 20px, 400),
    $caption:       mat-typography-level(12px, 20px, 400),
    $button:        mat-typography-level(14px, 14px, 500),
    $input:         mat-typography-level(inherit, 1.125, 400)
);

@include mat-base-typography($custom-typography);

// Override typography for a specific Angular Material components.
@include mat-checkbox-typography($custom-typography);

// Override typography for all Angular Material, including mat-base-typography and all components.
@include angular-material-typography($custom-typography);

@include mat-core($custom-typography);

Add this code on your main or base css file and change font name as per your need.

This will allow you to change the font family to "inherit":

@import '~@angular/material/theming';
$custom-typography: mat-typography-config(
  $font-family: 'inherit'
);
@include mat-core($custom-typography);

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