02-06-form-pseudo-classes-validity.html 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Form pseudo-classes</title>
  6. <style>
  7. body {
  8. font-family: "Helvetica Neue", Arial, sans-serif;
  9. }
  10. label, button {
  11. display: block;
  12. margin-top: 1em;
  13. font-size: 1em;
  14. }
  15. input {
  16. border: 1px solid #aaa;
  17. font-size: 1em;
  18. padding: 0.2em;
  19. outline-offset: 0;
  20. }
  21. input, button {
  22. line-height: 1.5em;
  23. padding: 0.25em;
  24. }
  25. input:required {
  26. border-color: black;
  27. }
  28. input:optional {
  29. border-color: #ccc;
  30. }
  31. input:valid {
  32. border-color: green;
  33. outline: 2px solid green;
  34. }
  35. input:invalid {
  36. border-color: red;
  37. outline: 2px solid pink;
  38. }
  39. .help-text {
  40. display: inline;
  41. font-style: italic;
  42. color: #999;
  43. }
  44. </style>
  45. </head>
  46. <body>
  47. <form action="." method="post" novalidate>
  48. <label for="field-name">Name:</label>
  49. <input type="text" name="field-name" id="field-name" required>
  50. <p class="help-text">Required</p>
  51. <label for="field-email">Email:</label>
  52. <input type="email" name="field-email" id="field-email">
  53. <p class="help-text">Optional</p>
  54. <label for="field-email-confirm">Confirm email:</label>
  55. <input type="email" name="field-email-confirm" id="field-email-confirm">
  56. <p class="help-text">Optional unless email field is filled in.</p>
  57. <button type="submit">Send</button>
  58. </form>
  59. </body>
  60. </html>