最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to remove angular mat-button-toggle hover effect? - Stack Overflow

programmeradmin0浏览0评论

I am trying to remove the default hover effect of the mat-button-toggle. But somehow, I am unable to override it. Whenever I hover over the button I get this white shady background.

The .html file:

<div class="header">
  <mat-button-toggle-group class="mat-menu" [value]=target>
    <mat-button-toggle (change)="redirekt($event.value)" value="/" [disableRipple]="true" class="mat-menu-item">Home</mat-button-toggle>
    <mat-button-toggle (change)="redirekt($event.value)" value="/test" [disableRipple]="true" class="mat-menu-item">Test</mat-button-toggle>
  </mat-button-toggle-group>
</div>
<div class="outlet">
  <router-outlet></router-outlet>
</div>

The .scss file:

.mat-menu {
  width: 100%;
  border: none !important;
  border-radius: 0px;
  position: relative;
  background: mat_color($primary);
  text-align: left;
}

.mat-menu-item {
  align-self: center;

  margin: 0px 8px;
  font-size: 15px;

  @media (min-width: 768px) {
    margin: 5px 8px;
    font-size: 20px;
  }

  border: none !important;
  color: white;

  &:hover, &:focus, &:active {
    background-color: transparent !important;
    @media only screen and (min-width: 768px) {
      -webkit-transform: scale(1.1);
      transform: scale(1.1);
    }
  }
}

.mat-button-toggle-checked {
    color: mat-color($accent) !important;
}

I am trying to remove the default hover effect of the mat-button-toggle. But somehow, I am unable to override it. Whenever I hover over the button I get this white shady background.

The .html file:

<div class="header">
  <mat-button-toggle-group class="mat-menu" [value]=target>
    <mat-button-toggle (change)="redirekt($event.value)" value="/" [disableRipple]="true" class="mat-menu-item">Home</mat-button-toggle>
    <mat-button-toggle (change)="redirekt($event.value)" value="/test" [disableRipple]="true" class="mat-menu-item">Test</mat-button-toggle>
  </mat-button-toggle-group>
</div>
<div class="outlet">
  <router-outlet></router-outlet>
</div>

The .scss file:

.mat-menu {
  width: 100%;
  border: none !important;
  border-radius: 0px;
  position: relative;
  background: mat_color($primary);
  text-align: left;
}

.mat-menu-item {
  align-self: center;

  margin: 0px 8px;
  font-size: 15px;

  @media (min-width: 768px) {
    margin: 5px 8px;
    font-size: 20px;
  }

  border: none !important;
  color: white;

  &:hover, &:focus, &:active {
    background-color: transparent !important;
    @media only screen and (min-width: 768px) {
      -webkit-transform: scale(1.1);
      transform: scale(1.1);
    }
  }
}

.mat-button-toggle-checked {
    color: mat-color($accent) !important;
}
Share Improve this question asked May 19, 2020 at 19:27 LeFroschLeFrosch 1111 gold badge2 silver badges13 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

In 2023 MatButtonModule, @angular/material version ^15.1.3, you can modify the CSS3 variables.

.mat-mdc-button {
  --mat-mdc-button-persistent-ripple-color: none;
}

Note you'll need to add encapsulation: ViewEncapsulation.None in your @Component decorator.

You should also change this style:

.mat-button-toggle-focus-overlay {
display: none;
}
发布评论

评论列表(0)

  1. 暂无评论