Validation in HTML5. :invalid classe after submit

前端 未结 9 2443
清歌不尽
清歌不尽 2021-02-18 14:11

I\'m building a form and I want to use the :invalid selector to give the \"required\" input fields a red border if the user presses submit without filling them, but

9条回答
  •  伪装坚强ぢ
    2021-02-18 14:35

    You can achieve this by chaining pseudo-classes:

    
    

    that way the input field will just show invalid styles only when that input field required and focused.

    Here is a helpful article: https://alistapart.com/article/forward-thinking-form-validation/

    Another stack overflow thread on this: https://stackoverflow.com/a/7921385/11102617

提交回复
热议问题