我正在尝试实现 Angular Material Typography,但是我遇到了一些困难,我不确定可能是什么问题。
我按照 Angular在这里提供的说明进行操作,但是遇到了问题。问题是,看起来应用程序中的所有内容都受到了影响,但是有些内容被默认排版覆盖,我不确定我做错了什么。
创建和使用的排版
$typography-configuration: mat-typography-config(
$font-family: 'Roboto, "Helvetica Neue", sans-serif',
$display-4: mat-typography-level(112px, 112px, 300),
$display-3: mat-typography-level(100px, 56px, 400),
$display-2: mat-typography-level(100px, 48px, 400),
$display-1: mat-typography-level(100px, 34px, 400),
$headline: mat-typography-level(100px, 32px, 400),
$title: mat-typography-level(100px, 32px, 500),
$subheading-2: mat-typography-level(100px, 28px, 400),
$subheading-1: mat-typography-level(100px, 24px, 400),
$body-2: mat-typography-level(100px, 24px, 500),
$body-1: mat-typography-level(100px, 22px, 400),
$caption: mat-typography-level(100px, 22px, 400),
$button: mat-typography-level(100px, 14px, 500),
$input: mat-typography-level(100px, 1.125, 400)
);
@include angular-material-typography($typography-configuration);
正如您在排版中看到的那样,我故意将第一个参数(字体大小)设置为100px
,以便我可以查看应用程序上的所有内容是否都受到影响。
示例 #1:材质按钮
对于 Angular Material 按钮(在 html 元素 'button' 上使用 'mat-button'),我看到了我所期望的,如下所示。文本设置为 100px。
示例 #2:工具栏
但是对于 Mat 工具栏,我没有看到字体大小设置为 100 像素。在我看来,如下所示的默认字体大小覆盖了 100px 大小:
示例 #3:具有多个覆盖的不同工具栏
对于另一个工具栏上的最后一个示例,我们可以看到 100px 被添加了几次,每次都相互覆盖,直到最后一个覆盖的也是 20px,所以字体大小不是 100px。
细节:
此处找到的 Angular Material 指南显示我们有 3 种在应用程序中使用排版的方法:
// Override typography CSS classes (e.g., mat-h1, mat-display-1, mat-typography, etc.).
@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);
据我了解,我使用的第三个选项应该适用于您使用的任何内容class="mat-typography"
。所以我将它添加到body
应用程序中,并在app-root
. 然而,正如我们在上面看到的,只有一些应用程序受到了正确的影响。
我尝试将它添加到组件中应用程序的较小部分,但结果是一样的。
我不确定我的理解是否错误并且我没有正确使用它或者其他地方是否存在问题,我假设我使用它错误但是我无法找到其他人创建的任何教程和示例令人惊讶。
我尝试将自己的类附加到诸如class="mat-display-1"
似乎工作正常的项目中,但是如果我必须在整个应用程序的任何地方应用它,这似乎不是一个好的解决方案。
如果可能的话,我希望它可以在整个应用程序中应用,而不必单独为排版设置 100 个类。
我知道我可以按照这里的建议将其应用于我自己在 sass 中的元素,但我认为他们自己会这样做。