The CSS input[value=whatever] selector doesn't seem to match against input.value. What am I missing?

前端 未结 2 1636
逝去的感伤
逝去的感伤 2021-01-27 17:04

N.B.: I should note that the proper solution to this is to just use the \'placeholder\' attribute of an input, but the question still stands.

Another N.B.: Since, as Qu

2条回答
  •  青春惊慌失措
    2021-01-27 17:49

    There are new pseudo classes for matching a number of properties of an input element

    • :valid
    • :invalid
    • :in-range
    • :out-of-range
    • :required

    A required element with no value set to it will match against :invalid. If you insist on using the value instead of placeholder, you could simply add a pattern or a customValidity function to force your initial value to be counted as invalid.

提交回复
热议问题