SCSS/CSS selector to select all input types

后端 未结 2 1007
借酒劲吻你
借酒劲吻你 2021-02-02 09:11

I have some input type has this scss setting (from the framework)

textarea,
input[type=\"text\"],
input[type=\"password\"],
input[type=\"datetime\"],
...
input[t         


        
2条回答
  •  南笙
    南笙 (楼主)
    2021-02-02 09:36

    Will this suffice?

    input[type="text"] {
        border: 1px red;
    }
    
    input[type] {
        border: 1px solid blue; }
    }
    

    They both have the same specificity, so the last one overrides.

    See jsFiddle: http://jsfiddle.net/TheNix/T2BbG/

    Another solution would be to ommit the element from the first selector. The latter would have higher specificity – however, you should know that in terms of performance, the first one is similar to using an universal selector (as it attempts to match all elements in the DOM, to check for the attribute).

    [type="text"] {
        border: 1px red;
    }
    
    input[type="text"] {
        border: 1px solid blue; }
    }
    

提交回复
热议问题