HTML5 Required input styling

前端 未结 7 1262
眼角桃花
眼角桃花 2020-11-30 11:13

In HTML 5, we can mark inputs as required and then select them with the [required] pseudo-selector in CSS. But I only want to style them when they

7条回答
  •  Happy的楠姐
    2020-11-30 11:26

    Very simple, just add the class when the element is in focus, then during the submit it gives focus on the elements that are incorrect and the client is filling and validating one by one I believe it is the best solution without using JavaScript.

    input:required:focus {
       border-color: palegreen;
    }
    input:invalid:focus {
       border-color: salmon;
    }
    

提交回复
热议问题