简体   繁体   English

通过 1 个特定的单个子菜单定位父菜单

[英]Target parent menu through 1 specific single sub menu

I'm trying to target my parent menu item through only 1 of my submenu items.我试图通过我的子菜单项中的 1 个来定位我的父菜单项。 The thing is, I only know how to target classes IN classes, not backwards.问题是,我只知道如何在类中定位类,而不是向后定位。 And I only want to target this parent through 1 of the submenus, not all of them.我只想通过子菜单中的 1 个来定位这个父级,而不是所有子菜单。

The reason: I have a sub menu item that is visible in more than one parent menu.原因:我有一个在多个父菜单中可见的子菜单项。 When this sub page is active "lid worden", all the parents become active.当这个子页面“lid worden”处于活动状态时,所有的父母都变得活跃。 So you will never know in what main menu you are as a visitor.所以你永远不会知道你作为访客在哪个主菜单中。 For this single page, I want to turn off the active style of the parent.对于这个单页,我想关闭父级的活动样式。 I already gave this single sub menu item a different class (.menu-lidworden).我已经为这个单个子菜单项提供了不同的 class (.menu-lidworden)。 So the css must be something like this所以 css 一定是这样的

.sub-menu.menu-lidworden.current_page_item -->.current-menu-parent .sub-menu.menu-lidworden.current_page_item -->.current-menu-parent
{ font-weight:normal etc... some other styles;} { font-weight:normal 等等...一些其他的 styles;}

I made 2 printscreens since the website is still under construction and offline.由于该网站仍在建设中且处于离线状态,因此我制作了 2 个打印屏幕。
https://dekeienatletiek.nl/hanneke/main-menu.png https://dekeienatletiek.nl/hanneke/main-menu.png
https://dekeienatletiek.nl/hanneke/main-menu-html.png https://dekeienatletiek.nl/hanneke/main-menu-html.png

As you can see, the menu "lid worden" is in the parent "nieuws & uitslagen" but also in "over the keien".如您所见,菜单“lid worden”位于父级“nieuws & uitslagen”中,但也在“over the keien”中。 In the future it will be in almost all the parents.将来几乎所有的父母都会这样做。 As I explained before, all of them will be active because of this.正如我之前解释的那样,所有这些都将因此而活跃起来。 And I dont want that.我不想要那个。

Hope somebody can help me with this.希望有人能帮我解决这个问题。 Thank you in advance先感谢您

You can try some javascript, by calling a function when triggering the click event (or other events depending on what you need ), this function check all the parents elements and remove any active CSS classes from them, and then assign the CSS classes to the parent only.您可以尝试一些 javascript,通过在触发点击事件(或其他事件,具体取决于您的需要)时调用 function,此 function 检查所有父元素并从中删除任何活动的 CSS 类,然后将 CSS 类分配给只有父母。

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

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