input:invalid css rule is applied on page load

守給你的承諾、 提交于 2019-12-05 07:31:24

Here's what you're looking for: http://jsfiddle.net/CaseyRule/16fuhf6r/2/

Style it like this:

form.submitted input:invalid{
    border-color:orange
}

And then add this js:

$('input[type="submit"]').click( function(){
    $('form').addClass('submitted');
});

I don't believe there is a way to achieve this yet without javascript.

In Firefox you can use:

:-moz-ui-invalid:not(output)

This the pseudo class added by the browser to give the red glow. It's not added at page load or all the inputs would have this glow. I've not found the equivalent in other browsers.

Maybe this works:

input:invalid{
    border-color:orange !important;
}

This will overwrite any other border colours assigned to the input when it's invalid.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!