我想编写一个CSS选择器规则,选择所有没有特定类的元素.例如,给定以下HTML:
<html class="printable">
<body class="printable">
<h1 class="printable">Example</h1>
<nav>
<!-- Some menu links... -->
</nav>
<a href="javascript:void(0)" onclick="javascript:self.print()">Print me!</a>
<p class="printable">
This page is super interresting and you should print it!
</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我想编写一个选择器来选择所有没有"可打印"类的元素,在这种情况下,它是nav和元素.
这可能吗?
注意:在我想要使用它的实际HTML中,将会有更多的元素没有 "可打印"类而不是(我在上面的例子中意识到它是另一种方式).
我正在研究CSS文件并发现需要设置文本输入框的样式,但是,我遇到了问题.我需要一个匹配所有这些元素的简单声明:
<input />
<input type='text' />
<input type='password' />
Run Code Online (Sandbox Code Playgroud)
......但不符合这些:
<input type='submit' />
<input type='button' />
<input type='image' />
<input type='file' />
<input type='checkbox' />
<input type='radio' />
<input type='reset' />
Run Code Online (Sandbox Code Playgroud)
这就是我想做的事情:
input[!type], input[type='text'], input[type='password'] {
/* styles here */
}
Run Code Online (Sandbox Code Playgroud)
在上面的CSS中,注意第一个选择器是input[!type]
.我的意思是我想选择未指定type属性的所有输入框(因为它默认为文本但input[type='text']
与之不匹配).不幸的是,我找不到CSS3规范中没有这样的选择器.
有谁知道这样做的方法?
如何编写CSS选择器选择没有特定属性的元素?
我有2个<div>
节点如下:
第一:
<div class="weEq5" style="will-change; width;">
<button class="_35EW6">
Run Code Online (Sandbox Code Playgroud)第二:
<div class="weEq5">
<button class="_35EW6">
Run Code Online (Sandbox Code Playgroud)我需要选择<div>
(具有相似的类)并且每个都具有相似的降序 <button>
但没有style
属性.
XPath似乎正常工作:
//div[@class and not (@style)]/button
Run Code Online (Sandbox Code Playgroud)
我正在寻找一个等效的CssSelector.
试验:
div[class :not(style)]>button (doesn't works).
Run Code Online (Sandbox Code Playgroud)
我经历了以下讨论,但他们似乎丢弃了class属性,:not([class])
如:
我正在寻找以类似的结尾:not(attribute)
.