简体   繁体   English

如何使用 Angular 材料密度?

[英]How can I use Angular Material density?

Material has created a density component modifier (Links here and here ).材料创建了一个密度分量修改器(链接在这里这里)。

I've imported material/density and followed the suggested code in my scss file:我已经导入了材料/密度并按照我的 scss 文件中的建议代码进行操作:

@use "@material/button";

.my-custom-button {
  // Sets button density scale to `-3`, i.e. button height to `24px`.
  @include button.density(-3);
}

but get errors about not finding the stylesheet.但会收到有关找不到样式表的错误。 I've scored the web and found no solution to this problem.我已经打分 web 并没有找到解决这个问题的方法。

With Angular 15 there is this guide https://material.angular.io/guide/theming#customizing-density so top of scss file you add use使用 Angular 15 有本指南https://material.angular.io/guide/theming#customizing-density所以在 scss 文件顶部添加使用

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

then add然后加

.my-custom-button {
  @include mat.button-density(-2);
}

I noticed that I needed to add that class to upper level element not to button itself.我注意到我需要将 class 添加到上层元素而不是按钮本身。 It might be some css selector problem.这可能是一些 css 选择器问题。 So make css selector strong enough.所以让 css 选择器足够强大。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM