【问题标题】:changing font on pre-built angular material theme在预先构建的角度材料主题上更改字体
【发布时间】:2020-04-27 17:58:29
【问题描述】:

是否可以更改预建的角材料主题的字体,例如。 G。 deeppurple-amber.css?

我只找到创建自定义主题的示例,您必须自己定义几乎所有内容。我真的只对设置自己的字体感兴趣。

【问题讨论】:

    标签: css angular-material


    【解决方案1】:

    请在下面找到更改默认字体的代码

    @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);
    

    将此代码添加到您的主要或基本 css 文件中,并根据需要更改字体名称。

    【讨论】:

    • 完美,非常感谢!!
    • 我的荣幸@user3629892
    • 你修改按钮字体大小成功了吗?
    • 对不起,我正在测试的是 mat-toggle-button 并且按钮字体由于某种原因不会影响它。也许这是错误。你怎么看?
    【解决方案2】:

    这将允许您将字体系列更改为“继承”:

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

    【讨论】:

    • “正确”答案对我不起作用,但这正是我所需要的,而且更干净。谢谢!
    • 我应该编辑哪个文件来包含这个代码 sn-p?我试图把它放在全局style.css,但它不起作用。
    • 好的,在我在行尾添加!important 后,它现在可以工作了。所以它看起来像这样:$font-family: 'Noto Sans !important'
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-11
    • 2019-02-28
    • 1970-01-01
    • 2022-11-28
    • 2019-06-15
    相关资源
    最近更新 更多