147

我遇到了很大的麻烦,因为我需要对某些输入类型进行样式化处理。我有类似的东西:

.registration_form_right input:not([type="radio")
{
 //Nah.
}

但我也不想设置复选框的样式。

我试过了:

.registration_form_right input:not([type="radio" && type="checkbox"])
.registration_form_right input:not([type="radio" && "checkbox"])
.registration_form_right input:not([type="radio") && .registration_form_right input:not(type="checkbox"])

如何使用&&?而且我需要尽快使用||,我认为用法会相同。

更新:我还是
不知道怎么正确使用。我在 W3 文档中找不到任何内容。||&&

4

8 回答 8

188

&&通过将多个选择器串在一起来工作,如下所示:

<div class="class1 class2"></div>

div.class1.class2
{
  /* foo */
}

另一个例子:

<input type="radio" class="class1" />

input[type="radio"].class1
{
  /* foo */
}

||通过使用逗号分隔多个选择器来工作,如下所示:

<div class="class1"></div>
<div class="class2"></div>

div.class1,
div.class2
{
  /* foo */
}
于 2010-05-09T08:59:38.200 回答
54

和 ( &&):

.registration_form_right input:not([type="radio"]):not([type="checkbox"])

或 ( ||):

.registration_form_right input:not([type="radio"]), 
   .registration_form_right input:not([type="checkbox"])
于 2010-05-09T08:48:04.440 回答
24

要选择元素的属性aAND :bX

X[a][b]

选择元素的属性aOR :bX

X[a],X[b]
于 2016-12-20T21:50:06.400 回答
4

:notIE 不支持伪类。我会得到这样的东西:

.registration_form_right input[type="text"],
.registration_form_right input[type="password"],
.registration_form_right input[type="submit"],
.registration_form_right input[type="button"] {
  ...
}

那里有一些重复,但为更高的兼容性付出的代价很小。

于 2010-05-09T08:52:31.880 回答
3

以防万一有人像我一样被卡住。经过帖子和一些点击和试用后,这对我有用。

input:not([type="checkbox"])input:not([type="radio"])
于 2014-02-19T19:09:32.947 回答
2

您可以使用 & 和 :not 以某种方式重现“OR”的行为。

SomeElement.SomeClass [data-statement="things are getting more complex"]  :not(:not(A):not(B))     {
    /* things aren't so complex for A or B */
}
于 2014-10-27T11:46:25.090 回答
1

我猜你讨厌写更多的选择器并用逗号分隔它们?

.registration_form_right input:not([type="radio"]),  
.registration_form_right input:not([type="checkbox"])  
{  
}

顺便说一句

not([type="radio" && type="checkbox"])  

在我看来更像是“没有这两种类型的输入”:)

于 2010-05-09T08:46:20.317 回答
1

一个警告。将几个not选择器串在一起增加了结果选择器的特异性,这使得覆盖变得更加困难:您基本上需要找到所有非选择器并将其复制粘贴到新选择器中。

选择器not(X or Y)可以很好地避免夸大特异性,但我想我们必须坚持结合对立面,就像在这个答案中一样。

于 2020-02-20T09:11:35.053 回答