Angular 17 上材质工具提示的自定义样式

问题描述 投票:0回答:1

我有一个带有最新 Material 组件的 Angular 17 应用程序。

我广泛使用工具提示组件,但在寻找如何自定义它时遇到问题。

我确实设法使用 CSS 中的以下代码更改字体大小:

$tt-typography: mat.define-typography-config(
    $caption: mat.define-typography-level(16px, 1, 400)
);

@include mat.tooltip-typography($tt-typography);

但这仅适用于字体大小和粗细。我还想自定义行高、工具提示的宽度等等。

我可以用这段代码做到这一点吗?如果是这样,我还可以为这些目标设置哪些选项?

我应该提到,我已经尝试了各种 CSS 选择器,这些选择器应该覆盖 Material 的默认值(如果可能的话,这显然是最简单和最简单的方法),但到目前为止还没有成功。

angular angular-material tooltip
1个回答
0
投票

define-typography-level
在源码中有如下定义

代码更改:

// `font-size`, `line-height`, `font-weight`, `font-family`, and `letter-spacing`.
$my-custom-typography-config: mat.define-typography-config(
  $caption:
    mat.define-typography-level(
      $font-size: 24px,
      $line-height: 24px,
      $font-weight: 400,
      $font-family: Helvetica,
      $letter-spacing: normal,
    ),
);

@include mat.tooltip-typography($my-custom-typography-config);

排版.md

## Typography levels

A **typography level** is a collection of typographic styles that corresponds to a specific
part of an application's structure, such as a header. Each level includes styles for font family,
font weight, font size, and letter spacing. Angular Material uses the [typography levels
from the 2018 version of the Material Design specification][2018-typography], outlined in the
table below.

| Name            | Description                                                  |
|-----------------|--------------------------------------------------------------|
| `headline-1`     | One-off header, usually at the top of the page (e.g. a hero header). |
| `headline-2`     | One-off header, usually at the top of the page (e.g. a hero header). |
| `headline-3`     | One-off header, usually at the top of the page (e.g. a hero header). |
| `headline-4`     | One-off header, usually at the top of the page (e.g. a hero header). |
| `headline-5`     | Section heading corresponding to the `<h1>` tag.             |
| `headline-6`     | Section heading corresponding to the `<h2>` tag.             |
| `subtitle-1`     | Section heading corresponding to the `<h3>` tag.             |
| `subtitle-2`     | Section heading corresponding to the `<h4>` tag.             |
| `body-1`         | Base body text.                                              |
| `body-2`         | Secondary body text.                                         |
| `caption`        | Smaller body and hint text.                                  |
| `button`         | Buttons and anchors.                                         |

[2018-typography]: https://m2.material.io/design/typography/the-type-system.html#type-scale

### Define a level

You can define a typography level with the `define-typography-level` Sass function. This function
accepts, in order, CSS values for `font-size`, `line-height`, `font-weight`, `font-family`, and
`letter-spacing`. You can also specify the parameters by name, as demonstrated in the example below.

```scss
@use '@angular/material' as mat;

$my-custom-level: mat.define-typography-level(
  $font-family: Roboto,
  $font-weight: 400,
  $font-size: 1rem,
  $line-height: 1,
  $letter-spacing: normal,
);
```

Stackblitz 演示

© www.soinside.com 2019 - 2024. All rights reserved.