【问题标题】:In CSS is there a selector for referencing a specific input type that also has a class?在 CSS 中是否有一个选择器用于引用也有一个类的特定输入类型?
【发布时间】:2012-12-23 23:09:17
【问题描述】:

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

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

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

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

我确定我在这里遗漏了一些简单的东西。提前致谢。

【问题讨论】:

    标签: css css-selectors


    【解决方案1】:

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

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

    input.some-class 则相反。

    【讨论】:

    • 太棒了。谢谢。我还刚刚发现 input[type="text"][class~="some-class"] 也可以,但我更喜欢您的解决方案,因为它更干净。
    • @Art Geigel:更好,因为它使用了正确的工具来完成这项工作......如果您知道可以使用类选择器来按类选择,那么只需使用类选择器!跨度>
    【解决方案2】:
        input[type="text"].some-class {
        ....
         } 
    

    "input[type="text"]" 和 ".some-class" 之间没有空格可以工作..

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

    【讨论】:

      猜你喜欢
      • 2011-11-14
      • 1970-01-01
      • 2011-07-14
      • 2016-10-08
      • 2011-02-09
      • 2013-08-07
      • 1970-01-01
      • 2021-02-05
      • 2012-01-07
      相关资源
      最近更新 更多