Specify multiple attribute selectors in CSS

后端 未结 5 628

What is the syntax for doing something like:

input[name=\"Sex\" AND value=\"M\"]

Basically, I want to select the input element

5条回答
  •  天命终不由人
    2020-11-27 10:48

    Simple input[name=Sex][value=M] would do pretty nice. And it's actually well-described in the standard doc:

    Multiple attribute selectors can be used to refer to several attributes of an element, or even several times to the same attribute.

    Here, the selector matches all SPAN elements whose "hello" attribute has exactly the value "Cleveland" and whose "goodbye" attribute has exactly the value "Columbus":

    span[hello="Cleveland"][goodbye="Columbus"] { color: blue; }

    As a side note, using quotation marks around an attribute value is required only if this value is not a valid identifier.

    JSFiddle Demo

提交回复
热议问题