如何编写CSS选择器来选择不具有特定属性的元素? [英] How to write a CSS Selector selecting elements NOT having a certain attribute?
问题描述
如何编写CSS选择器以选择不具有特定属性的元素?
How to write a CSS Selector selecting elements NOT having a certain attribute?
我有2个< div>
节点,如下所示:
I have 2 <div>
nodes as follows:
-
第一个:
First:
<div class="weEq5" style="will-change; width;">
<button class="_35EW6">
第二个:
Second:
<div class="weEq5">
<button class="_35EW6">
我需要选择< div>
(具有相似的类),并且每个都有类似的 descending < button>
,但没有 style
属性.
I need to select the <div>
(with the similar class) and each of them which have a similar descending <button>
but without the style
attribute.
XPath 似乎可以正常工作,
//div[@class and not (@style)]/button
我正在寻找等效的 CssSelector .
试用:
div[class :not(style)]>button (doesn't works).
我已经通过以下讨论,但是他们似乎正在将 class 属性作为:not([class])
丢弃,如下所示:
I have been through the following discussion but they seem to be discarding the class attribute as :not([class])
as in:
- 我可以写吗一个CSS选择器选择没有特定类的元素?
- 我在寻找以
:not(attribute)
结尾的类似行.I was looking in similar lines ending with
:not(attribute)
.推荐答案
我认为更准确的CSS选择器是:
I think more accurate CSS Selector is:
div[class]:not([style])>button
因为
button
元素是div
元素的子元素.because the
button
element is a child ofdiv
element.希望它对您有帮助!
这篇关于如何编写CSS选择器来选择不具有特定属性的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!