问题描述
在CSS(任何版本)中,是否有类似的东西,或任何其他方式做任何像:has()
选择器在jQuery?
不,没有。 CSS的设计方式,不允许选择器匹配祖先或前面的兄弟姐妹;只有后代(
和>
),后续兄弟(〜
和 +
)或特定子级(:* - 子级
)。唯一的祖先选择器是:root
伪类,它选择文档的根元素(在HTML页面中,自然会是 html
)。
如果您需要将样式应用于您使用查询的元素:has()
,您需要添加一个CSS类,然后通过该类进行风格,。 p>
In CSS (any version), is there something like, or any other way of doing anything like the :has()
selector in jQuery?
http://api.jquery.com/has-selector/
No, there isn't. The way CSS is designed, does not permit selectors that match ancestors or preceding siblings; only descendants ( and
>
), succeeding siblings (~
and +
) or specific children (:*-child
). The only ancestor selector is the :root
pseudo-class which selects the root element of a document (in HTML pages, naturally it would be html
).
If you need to apply styles to the element you're querying with :has()
, you need to add a CSS class to it then style by that class, as suggested by Stargazer712.
这篇关于CSS有什么像jQuery的:has()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!