You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular中Material Design的mat-select不响应density属性问题

Angular Material mat-select 密度设置不生效问题

我在Angular应用中使用Material Design框架,尝试通过主题的density属性实现紧凑布局时发现:按钮等组件设置密度后均生效,但mat-select始终保持原有尺寸,无法达到紧凑效果。

使用的mat-select代码

<mat-form-field appearance="fill">
    <mat-label>Granularität</mat-label>
    <mat-select [(value)]="this.settings.granularity">
        <mat-option value="day">täglich</mat-option>
        <mat-option value="week">wöchentlich</mat-option>
    </mat-select>
</mat-form-field>

尝试的两种无效方案

  • 单独设置select密度
@include mat.select-density(-3);
  • 全局主题中配置density
$my-app-theme: mat.define-light-theme((
        color: (primary: $my-app-primary, accent: $my-app-accent, warn: $my-app-warn),
        typography: mat.define-typography-config(),
        density: -3,
    ));

设置完成后,mat-select仍保持较大尺寸:
mat-select尺寸未变化

内容的提问来源于stack exchange,提问作者Konrad

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 04:52:09