test.html 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Single Input Multi-Box Visual</title>
  7. <style>
  8. body {
  9. font-family: Arial, sans-serif;
  10. display: flex;
  11. justify-content: center;
  12. align-items: center;
  13. min-height: 100vh;
  14. background-color: #f0f0f0;
  15. margin: 0;
  16. }
  17. .input-wrapper {
  18. position: relative;
  19. width: 250px; /* Adjust based on desired number of boxes and character width */
  20. height: 50px; /* Height of the overall input area */
  21. box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  22. border-radius: 8px;
  23. overflow: hidden; /* Important to clip the text if it overflows slightly */
  24. }
  25. .single-char-input {
  26. width: 100%;
  27. height: 100%;
  28. padding: 0;
  29. margin: 0;
  30. border: none;
  31. background: transparent;
  32. font-size: 32px; /* Larger font size for visibility */
  33. letter-spacing: 25px; /* Adjust this to control spacing between characters */
  34. text-align: start;
  35. outline: none;
  36. font-family: 'Courier New', Courier, monospace; /* Crucial for fixed-width characters */
  37. color: #333;
  38. caret-color: #007bff; /* Color of the blinking cursor */
  39. box-sizing: border-box; /* Include padding/border in width/height */
  40. }
  41. /* Create the "boxes" using a pseudo-element and background-image */
  42. .input-wrapper::after {
  43. content: '';
  44. position: absolute;
  45. top: 0;
  46. left: 0;
  47. width: 100%;
  48. height: 100%;
  49. pointer-events: none; /* Allows clicks to pass through to the input */
  50. background-image:
  51. linear-gradient(to right, #ccc 2px, transparent 2px); /* Vertical lines */
  52. background-size: calc(100% / 6) 100%; /* Divides the width into 6 equal parts for lines */
  53. background-repeat: repeat-x; /* Repeat the vertical lines */
  54. border: 2px solid #ccc; /* Outer border for the entire input area */
  55. border-radius: 8px;
  56. box-sizing: border-box; /* Match input's box-sizing */
  57. transition: border-color 0.2s ease-in-out;
  58. }
  59. /* Highlight the pseudo-element border on focus of the input */
  60. .single-char-input:focus + .input-wrapper::after {
  61. border-color: #007bff;
  62. box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.25);
  63. }
  64. /* You might need to adjust letter-spacing and width/height more precisely
  65. based on the exact font and number of characters you expect.
  66. For example, if you want 6 characters:
  67. (width - (number_of_chars - 1) * letter_spacing) / number_of_chars
  68. This can get tricky quickly.
  69. */
  70. </style>
  71. </head>
  72. <body>
  73. <div class="input-wrapper">
  74. <input type="text" class="single-char-input" maxlength="6"
  75. pattern="[0-9]*" inputmode="numeric" placeholder="______">
  76. </div>
  77. </body>
  78. </html>