css - 在预建的 Angular Material 主题上更改字体

标签 css angular-material

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

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

最佳答案

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

@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 文件或基本 CSS 文件中,并根据需要更改字体名称。

关于css - 在预建的 Angular Material 主题上更改字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51592472/

相关文章:

css - 带有 5 个图像的水平导航栏,CSS

css - BlueprintJS 未加载其图标 CSS 模块,但能够加载核心 CSS 模块

javascript - jQuery 平滑滚动到 anchor

javascript - 取消按键拖动 Angular cdk Drag and Drop

angularjs - 同时使用 Angular Material 和 Kendo ui 的项目?

angular - 是否可以使用 ng-content 将 mat-options 传递给我的自定义 mat-select 组件?

css - Angular 4 - 如何使垫卡填充整个父组件区域

javascript - 当用户离开字段时检查有效性并应用样式

html - md-next-button 不适用于 Angular Material

html - 对齐动态生成的 div