我正在尝试从 WordPress 默认侧边栏菜单中选择子菜单项,并且我正在尝试为此编写一个 CSS 选择器。我以为我了解 CSS 选择器,但我不知道这种情况下发生了什么。
以下是有效的:
.widget_nav_menu ul .menu-item .sub-menu { background: red; }
.widget_nav_menu ul .menu-item li { background: red; }
虽然这个不起作用:
.widget_nav_menu ul .menu-item li .sub-menu { background: red; }
有人可以向我解释一下为什么我不能在此处指定类和类型来更精确地指定事物吗?
幸运的是在这个定制级别我不需要更精确地选择内容(我只想隐藏子菜单项),但是有人可以告诉我如何使非工作示例正常工作吗?
这是一个 实时站点,但在所有带有 TwentyTen 主题和多主题的 WordPress 安装上都是相同的左侧的级别菜单。
更新:我想我对CSS中空格的使用有很大的误解,所以我在这里问了一个问题:CSS 文件中空格的使用
顺便说一句,在理解答案并意识到我的问题出了什么问题之后,我的问题的正确答案是:
.widget_nav_menu li.menu-item ul.sub-menu
I am trying to select the sub-menu item from a Wordpress default sidebar menu, and I am trying to write a CSS selector for that. I thought I understand CSS selectors, but I don't know what is happening in this case.
The following ones are working:
.widget_nav_menu ul .menu-item .sub-menu { background: red; }
.widget_nav_menu ul .menu-item li { background: red; }
While this one doesn't work:
.widget_nav_menu ul .menu-item li .sub-menu { background: red; }
Can someone explain to me why can I not specify things to be more precise with both specifying class and type here?
Luckily at this level of customization I don't need to select things more precisely (I only want to hide sub-menu items), but can someone tell me how to make the non-working example work?
Here is a live site, but it’s the same on all Wordpress installs with TwentyTen theme and a multi-level menu on the left.
UPDATE: I think I got a big misunderstanding about the usage of spaces in CSS, so I asked a question here: usage of spaces in CSS files
BTW, after understanding the answers and realising what was wrong with my problem, the correct answer for my problem is:
.widget_nav_menu li.menu-item ul.sub-menu
发布评论
评论(3)
尝试:
因为
sub-menu
类属于ul
并且li
之后没有sub-menu
类try:
because
sub-menu
class belongs toul
and there is nosub-menu
class afterli
我相信你想要这个:
I believe you want this:
试试这个:
因为 li 项目位于 .sub-menu ul 下面...
Try this :
Because the li item is below the .sub-menu ul...