md-menu override default max-width in Angular 2

 ̄綄美尐妖づ 提交于 2019-12-04 03:32:14

Set the View Encapsulation to None on your component:

@Component({
    templateUrl: './my.component.html' ,
    styleUrls: ['./my.component.css'], 
    encapsulation: ViewEncapsulation.None,
})

Then in your component css you can do exactly what you tried:

.mat-menu-panel.notifications-dropdown {
    max-width:none;
    width: 100vw; 
    margin-left: -8px;
    margin-top: 24px;
    overflow: visible;
}

.notification-row{
    width: 424px;
}

View Encapsulation = None means that Angular does no view encapsulation. Angular adds the CSS to the global styles. The scoping rules, isolations, and protections discussed earlier don't apply. This is essentially the same as pasting the component's styles into the HTML.

In some cases the wrapper over .mat-menu-panel can be .cdk-overlay-pane, in that case css should be something like this.

.cdk-overlay-pane.mat-menu-panel {
    max-width: your_custom_value
}

Due to the css specificity rules, 2 classes of specificity are required in order to override the defaults.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!