【问题标题】:Customize Angular Material component dimensions自定义 Angular Material 组件尺寸
【发布时间】:2021-02-03 08:35:18
【问题描述】:

我正在尝试自定义 Angular Material 按钮的大小(即填充)。这些值的定义来自_button-base.scss 中名为$mat-button-padding 的变量。但是,它直接包含在button.ts 中。有没有可能调整这个值?

我已经尝试在包含材质主题之前覆盖它(因为变量是使用!default 定义的),但它没有效果,因为样式直接包含在按钮组件中。除了手动覆盖它并生成重复样式(基本上是覆盖按钮样式的附加 css 定义)之外,还有其他选项吗?

高度赞赏任何想法。

【问题讨论】:

  • 你能不能只覆盖定义的样式。如果您对填充不满意,您必须在某处定义您想要的内容?类似(未测试)::ng-deep .mat-button {padding: 0 27px!important}。

标签: css angular sass angular-material material-design


【解决方案1】:
You can add own class in "mat-button" element like below and you can apply your own css.

<button mat-stroked-button 
color="primary" 
class="common-button">Button</button>

.common-button {
  border-radius: 4px;
  line-height: 2.5;
  height: 80px;
}

【讨论】:

  • 你是对的,这是一个解决方案。但我希望能提出一个不需要覆盖或额外 CSS 而是首先生成正确的 CSS。
猜你喜欢
  • 2016-05-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-11-26
  • 1970-01-01
  • 2020-11-11
  • 2014-05-02
  • 2020-03-27
相关资源
最近更新 更多