是否有CSS父选择器?

耗尽温柔 提交于 2020-08-14 02:39:08

问题:

How do I select the <li> element that is a direct parent of the anchor element? 如何选择作为锚元素直接父元素的<li>元素?

As an example, my CSS would be something like this: 例如,我的CSS将是这样的:

li < a.active {
    property: value;
}

Obviously there are ways of doing this with JavaScript, but I'm hoping that there is some sort of workaround that exists native to CSS Level 2. 显然,可以使用JavaScript进行此操作,但是我希望CSS Level 2本身具有某种解决方法。

The menu that I am trying to style is being spewed out by a CMS, so I can't move the active element to the <li> element... (unless I theme the menu creation module which I'd rather not do). 我尝试设置样式的菜单已由CMS弹出,因此我无法将active元素移至<li>元素...(除非我将菜单创建模块作为主题,但我不希望这样做) 。

Any ideas? 有任何想法吗?


解决方案:

参考一: https://stackoom.com/question/4G0j/是否有CSS父选择器
参考二: https://oldbug.net/q/4G0j/Is-there-a-CSS-parent-selector
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!