CSS"和"和"或"

Mis*_*iur 92 css css-selectors conditional-operator

我遇到了很大的麻烦,因为我需要通过设计一些输入类型来解决问题.我有类似的东西:

.registration_form_right input:not([type="radio")
{
 //Nah.
}
Run Code Online (Sandbox Code Playgroud)

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

我试过了:

.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"])
Run Code Online (Sandbox Code Playgroud)

怎么用&&?我需要尽快使用||,我认为使用方法是一样的.

更新:
我仍然不知道如何使用||&&正确.我在W3文档中找不到任何内容.

geo*_*lee 124

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

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

div.class1.class2
{
  /* foo */
}
Run Code Online (Sandbox Code Playgroud)

另一个例子:

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

input[type="radio"].class1
{
  /* foo */
}
Run Code Online (Sandbox Code Playgroud)

|| 通过使用逗号分隔多个选择器来工作:

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

div.class1,
div.class2
{
  /* foo */
}
Run Code Online (Sandbox Code Playgroud)

  • 谁现在使用IE :) (11认同)
  • 这是Internet Explorer支持的有用图表:http://msdn.microsoft.com/en-us/library/cc351024(VS.85).aspx #selectors (5认同)
  • `not`似乎从IE9开始工作(感谢@geofflee提供的图表). (2认同)
  • 2018 年我们真的还在担心支持旧版本的 IE 吗?连微软也不知道。 (2认同)

ken*_*ytm 41

AND(&&):

.registration_form_right input:not([type="radio"]):not([type="checkbox"])
Run Code Online (Sandbox Code Playgroud)

或(||):

.registration_form_right input:not([type="radio"]), 
   .registration_form_right input:not([type="checkbox"])
Run Code Online (Sandbox Code Playgroud)

  • @Misiur:我不明白. (2认同)

小智 14

要选择性质abA的X元素:

X[a][b]
Run Code Online (Sandbox Code Playgroud)

要选择的属性ab一个的X元素:

X[a],X[b]
Run Code Online (Sandbox Code Playgroud)


Max*_*keh 5

: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"] {
  ...
}
Run Code Online (Sandbox Code Playgroud)

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


que*_*ing 5

如果我们想查找在其属性中div同时包含this that 的valuea ,我们可以简单地连接这两个条件,如下所示:

div[value*="this"][value*="that"] 
Run Code Online (Sandbox Code Playgroud)

如果我们想要divthat 包含this OR that,您可以在两个条件之间使用逗号,如下所示:

div[value*="this"], div[value*="that"] 
Run Code Online (Sandbox Code Playgroud)

注意:您可以根据需要使用任意多个条件。这绝不限于示例中所示的 2。