简体   繁体   English

离子:在离子菜单中隐藏背景

[英]Ionic: hide backdrop in ion-menu

I have an Ionic app using an ion-menu to open a burger menu.我有一个 Ionic 应用程序,它使用离子菜单打开汉堡菜单。 However, I don't want to have the backdrop on the right as shown in this screenshot:但是,我不想在右侧显示此屏幕截图所示的背景:

在此处输入图片说明

What I want to have is this (without the backdrop):我想要的是这个(没有背景):

在此处输入图片说明

The ion-menu:离子菜单:

<ion-menu side="start" type="push" menuId="first" contentId="main" class="burger-menu">...</ion-menu>

I've tried about everything in CSS:我已经尝试了 CSS 中的所有内容:

.burger-menu {
  // Doesn't work
  --backdrop: none !important;
  backdrop-filter: none !important;
}

// Doesn't work
ion-menu#backdrop {
  display: none !important;
}

// Doesn't work
ion-menu > ion-backdrop {
  display: none !important;
}

// Doesn't work
ion-backdrop.menu-backdrop {
  display: none !important;
}

// Doesn't work
:host(.menu-type-push) .show-backdrop {
  display: none !important;
}

But none of them seem to work.但它们似乎都不起作用。

EDIT: here's what I'm seeing in the console when I open the menu.编辑:这是我打开菜单时在控制台中看到的内容。 在此处输入图片说明

The backdrop is inside the shadow tree of the ion-menu element, which means CSS will not work. backdrop位于ion-menu元素的阴影树内,这意味着 CSS 将不起作用。

According to the documentation about ion-menu , the backdrop is a CSS Shadow Part being exposed.根据有关ion-menu文档backdrop是暴露的 CSS 阴影部分。 Therefore, you can use the ::part() pseudo-element which allows you to select elements inside of a shadow tree in order to style them.因此,您可以使用::part()伪元素,它允许您选择阴影树内的元素以设置它们的样式。

ion-menu::part(backdrop) {
    background-color: transparent;
}

Learn more about CSS Shadow Parts when styling the Ionic Framework.在设置 Ionic 框架样式时了解有关CSS Shadow Parts 的更多信息。

Edit编辑

It looks like the CSS Shadow Parts are not implemented in versions prior to Ionic 5.看起来 CSS Shadow Parts 在 Ionic 5 之前的版本中没有实现。
You can override the --ion-backdrop-color variable instead.您可以改写--ion-backdrop-color变量。

global.scss global.scss

:root {
  ion-menu {
    --ion-backdrop-color: transparent;
  }
}

Working fine on Ionic 4.在 Ionic 4 上运行良好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM