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

如何在Angular 18中修改mat-select的悬停下划线颜色?

实现mat-select悬停时下划线变白

要让鼠标悬停在mat-select组件上时,下划线变为白色,你需要修改CSS,结合hover伪类和目标元素选择器:

.mat-form-field:hover .mdc-line-ripple::after {
  transform: scaleX(1) !important;
  opacity: 1 !important;
  background-color: white !important;
}

完整代码示例

HTML代码:

<h4>Basic native select</h4>
<mat-toolbar class="header">
  <mat-form-field style="padding-top:20px">
    <mat-label style="color:white">Choose an option</mat-label>
    <mat-select>
      <mat-option value="option1">Option 1</mat-option>
    </mat-select>
  </mat-form-field>
</mat-toolbar>

CSS代码:

.mat-form-field:hover .mdc-line-ripple::after {
  transform: scaleX(1) !important;
  opacity: 1 !important;
  background-color: white !important;
}

关键说明

  • 通过.mat-form-field:hover定位到悬停状态的表单容器,确保样式仅在鼠标悬停时生效
  • 给mdc-line-ripple::after设置background-color: white,直接修改下划线颜色
  • 保留原有的transform和opacity属性,维持下划线的展开显示状态

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.19 04:42:07