HTML5 Required input styling

前端 未结 7 1274
眼角桃花
眼角桃花 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条回答
  •  旧时难觅i
    2020-11-30 11:26

    This solution will style input fields that are required via attribute while blank. Browsers will remove the :invalid pseudo class when populating a required field on keydown. Recent versions of Firefox automatically apply something similar to this style but Chrome and IE do not.

    input[required]:invalid { box-shadow: 0 0 3px 1px red }
    

    Try it: http://jsfiddle.net/2Ph2X/

提交回复
热议问题