向垫菜单添加自定义类 [英] adding a custom class to a mat-menu

查看:144
本文介绍了向垫菜单添加自定义类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我的应用程序使用了几个菜单,为此使用了有角材质的mat-menu组件.我可以通过在全局CSS文件中为菜单原始类编写CSS代码来更改所有菜单的样式.但是当我想使用.custom-class-name .original-material-class-name {}向其中一种添加特定样式时,则不会将这些样式应用于该菜单.

I use several menus for my app and I use angular material mat-menu component for this. I can change the style of all menus by writing css code in my global css file for menu original classes. but when I want to add some specific styles to one of them using .custom-class-name .original-material-class-name{} it doesn't apply those styles to that one menu.

这是stackblitz中的整个应用程序:应用程序

here's the whole app in stackblitz: app

header.component.html:

header.component.html:

<div>
<a mat-button class="theme-menu-toggle-button" *ngIf="!menuAvailable" 
(click)="changeSidenavMode(!mode)">
  <mat-icon>menu</mat-icon>
</a>
<a href="#" fxHide.lt-md fxShow.gt-sm class="theme-user" mat-button 
[matMenuTriggerFor]="menu">
  <img src="assets/images/user.png" class="theme-profile-image rounded-circle">
  <span class="theme-profile-title">نام نام‌خانوادگی</span>
</a>
<mat-menu #menu="matMenu" class="profile-menu">
  <button mat-menu-item *ngFor="let option of profileOptions">
    <mat-icon>{{option.icon}}</mat-icon>
   <span>{{option.title}}</span>
  </button>
</mat-menu>

styles.css:

styles.css:

.profile-menu .cdk-overlay-pane::before{
 width: 0;
 height: 0;
 border-left: 8px solid transparent;
 border-right: 8px solid transparent;
 border-bottom: 15px solid #5E35B1;
 content: " ";
 position: absolute;
 top: 10px !important;
 animation: fadeInRightBig 0.75s;
}

推荐答案

在backgroundClass的mat菜单中添加自定义类:

Add custom class in the mat-menu in backdropClass:

   <button mat-button [matMenuTriggerFor]="menu">Menu</button>
    <mat-menu #menu="matMenu" backdropClass="custom__menu">
      <button mat-menu-item>Item 1</button>
      <button mat-menu-item>Item 2</button>
    </mat-menu>

    .custom__menu + * .cdk-overlay-pane > div.mat-menu-panel > div.mat-menu-content {
      background-color: #777;
      button.mat-menu-item {
        color: white;
      }
    }

这篇关于向垫菜单添加自定义类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆