移动菜单 Wordpress 的两个问题 CSS

Two problems with mobile menu Wordpress CSS

我从博客中复制了一些代码并调整了一些代码,使我在 Wordpress 上的网站的移动菜单全屏显示。我为手机和平板电脑视图制作了全屏。但是有两个问题。

  1. 当我打开菜单时,我无法关闭菜单,因为关闭按钮和 'X' 在菜单叠加层下方,我尝试了一些带有 z-index 的东西但没有成功。如何使关闭按钮 'X' 在菜单打开时始终可见且可点击?

  2. 当我打开菜单时,我希望菜单被锁定,因此无法向下滚动和查看内容,但是当您打开菜单时,您只能看到菜单而不能除非您关闭菜单,否则能够向下滚动。我该如何解决这个问题?

这是平板电脑上的菜单 phone

Link 到网站->

https://vpwebdesign.disoh.nl/template-b/

我使用的代码:

/* Text left of hamburger in the Theme Builder */
.et_mobile_nav_menu:before  {
content: 'MENU';
position: absolute;
right: 40px;
z-index: 9999;
}

/* Text left of hamburger in Divi 3 */
#et_mobile_nav_menu:before  {
content: 'MENU';
position: absolute;
right: 33px;
bottom:30px;
}

/* X icon in expanded mobile menu */
.mobile_nav.opened .mobile_menu_bar:before {
content: "d";
}

/* Remove the top line in the mobile menu*/
.et_mobile_menu {
border-top:0px;
}

/* Center-align moble menu items */
.et_mobile_menu li {
text-align:center !important;
}
  
.et_mobile_menu li li, .et_mobile_menu li ul {
padding-left:0px !important;
}

/* Make mobile menu fullwidth */
.et_mobile_menu {
min-width: 100vw;
margin-left: -10vw;
}

/* Make the mobile menu full height */
.et_mobile_menu {
min-height:100vh !important;
min-height: -webkit-fill-available;
padding-top:150px !important;
margin-top:-150px!important;
}

html {
height: -webkit-fill-available;
}

对于您的第一个问题(访问关闭按钮点击),您可以像这样使用 pointer-events 属性:

ul.et_mobile_menu{pointer-evens:none;}
ul.et_mobile_menu li{pointer-evens:all;}

对于另一个问题(不要使 body 滚动),您可以在 open/close 菜单时在 body 上添加一个 class :

body.menu-open{ position:fixed; }

第二点的难点是找到在“mobile_nav”上附加“closed/opened”class的点击事件,并写一个小的JS脚本到attach/remove class 目前在 body 上,以便可以应用 CSS。

通常在 wordpress 上,JS 文件存放在主题或插件文件夹中。

首先感谢您的回答!

For your first question (access to close button click), you can play with the pointer-events attribute like this :

ul.et_mobile_menu{pointer-evens:none;} ul.et_mobile_menu li{pointer-evens:all;}

它确实使它可以点击,但是文本菜单和关闭按钮 'X' 仍然在视觉上位于菜单下方,如何使它们更显眼以便突出?

For the other question (don't make the body scroll), you can add a class on the body when you open/close the menu :

body.menu-open{ position:fixed; } Difficulty for second point is to find the click event that attach "closed/opened" class on "mobile_nav" and write a little JS script to attach/remove the class on the body at this moment in order the CSS can be applied.

Usually on a wordpress the JS files are stocked in the theme or plugin folder.

我会试试的,对我来说有点难,但我会试一试。