Is it possible to use an input value attribute as a CSS selector?

后端 未结 9 2241
[愿得一人]
[愿得一人] 2020-11-27 17:07

Is it possible to use a CSS selector to target an input that has a specific value?

Example: How can I target the input below based on the value=\"United States

9条回答
  •  有刺的猬
    2020-11-27 17:42

    It is possible, if you're using a browser which supports the CSS :valid pseudo-class and the pattern validation attribute on inputs -- which includes most modern browsers except IE9.

    For instance, to change the text of an input from black to green when the correct answer is entered:

    input {
      color: black;
    }
    input:valid {
      color: green;
    }

    Which country has fifty states?

提交回复
热议问题