在CSS中是否有一个选择器用于引用也具有类的特定输入类型?

Art*_*gel 39 css css-selectors

基本上我想要一个CSS选择器来抓取所有输入[type ="text"],但它也有一个类"some-class".

以下两项似乎都不适合我:

input[type="text"] .some-class {}    /* doesn't work */

.some-class input[type="text"] {}    /* doesn't work */
Run Code Online (Sandbox Code Playgroud)

我确定我在这里错过了一些简单的东西.提前致谢.

wle*_*ss1 89

你要 input.some-class[type="text"]

.some-class input寻找作为后代的输入标签.some-class.

input.some-class 反过来.

  • @Art Geigel:它更好,因为它使用正确的工具来完成工作......如果您知道可以使用类选择器按类进行选择,那么只需使用类选择器! (2认同)

Has*_*teq 17

    input[type="text"].some-class {
    ....
     } 
Run Code Online (Sandbox Code Playgroud)

在"input [type ="text"]"和".some-class"之间没有空格将起作用..

input [type ="text"] - 中间的空格是问题 - .some-class {}