02-05-form-pseudo-required.html 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. .help-text {
  32. display: inline;
  33. font-style: italic;
  34. color: #777;
  35. }
  36. </style>
  37. </head>
  38. <body>
  39. <form action="." method="post" novalidate>
  40. <label for="field-name">Name:</label>
  41. <input type="text" name="field-name" id="field-name" required>
  42. <p class="help-text">Required</p>
  43. <label for="field-email">Email:</label>
  44. <input type="email" name="field-email" id="field-email">
  45. <p class="help-text">Optional</p>
  46. <label for="field-email-confirm">Confirm email:</label>
  47. <input type="email" name="field-email-confirm" id="field-email-confirm">
  48. <p class="help-text">Optional unless email field is filled in.</p>
  49. <button type="submit">Send</button>
  50. </form>
  51. </body>
  52. </html>