Skip to content
Advertisement

e-mail span drops down after entering invalid e-mail address in the ‘contact’ form

How can I make ‘E-mail’ span stay on the top pink

JavaScript
JavaScript

? Is there anything else I can use instead of ‘valid’? I know that ‘E-mail” span drops down because it is not valid e-mail but even if someone writes invalid e-mail I want it to be still pink on the top but in the same time, when I press ‘send’ button I want the chrome say that it is not valid. Please see my code so maybe you could

When I write ‘dhdhd’ <- invalid e-mail and go to the next box, the pink ‘E-mail’ span drops down and becomes grey. It will only work if I write valid e-mail e.g ‘dfghj@gmail.com’ but I still want this ‘e-mail’ span to stay on the top even if it is invalid

Advertisement

Answer

You could just use the :invalid pseudo-class which would work, although I think it would display it as pink all the time. I don’t think you can achieve your desired outcome without using JavaScript unless you target input[value=""] (i.e. empty input).

Just a quick note that you should use a proper <label> element and associate it to the field for accessibility.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement