“包含 bar 的 foo"的 CSS 选择器? [英] CSS selector for "foo that contains bar"?

查看:23
本文介绍了“包含 bar 的 foo"的 CSS 选择器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法制作符合以下内容的 CSS 选择器?

Is there a way to make a CSS Selector that matches the following?

All OBJECT elements
  which have a PARAM element inside of them

选择器

OBJECT PARAM

不起作用,因为它匹配 PARAM,而不是 OBJECT.我想将 { display:none } 应用于对象;将其应用于 PARAM 是没有用的.

doesn't work, as it matches the PARAM, not the OBJECT. I'd like to apply { display:none } to the objects; it's useless to apply that to the PARAMs.

(我知道我可以使用 jQuery - $("object param").closest("object") - 和 VanillaJS - document.querySelector("objectparam").closest("object") - 但我正在尝试在页面上创建 CSS 规则.)

(I'm aware I could pull this off with jQuery - $("object param").closest("object") - and VanillaJS - document.querySelector("object param").closest("object") - but I'm trying to create CSS rules on a page.)

推荐答案

不,您要查找的将称为 父选择器.CSS 没有;它们已被多次提出,但我不知道包括它们在内的现有或即将推出的标准.您是正确的,您需要使用 jQuery 之类的东西或使用额外的类注释来实现您想要的效果.

No, what you are looking for would be called a parent selector. CSS has none; they have been proposed multiple times but I know of no existing or forthcoming standard including them. You are correct that you would need to use something like jQuery or use additional class annotations to achieve the effect you want.

这里有一些类似的问题,结果相似:

Here are some similar questions with similar results:

这篇关于“包含 bar 的 foo"的 CSS 选择器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆