I have an input type password that only allow a six-digit number like this:
<fieldset>
<label for="password-input">Enter New Pin</label>
<input type="password" name="password" id="password-input" inputmode="numeric" minlength="6"
maxlength="6" size="6" value="">
<span class="hint">New pin must be 6 digit number only</span>
</fieldset>
It will show like this:
How can I style it so it can look like the following?
To Solve the problem:
::after
onfieldset
instead ofinput
box or add an element.content
value using underscores, and position the elements.letter-spacing
andwidth
toinput
box, and set:focus
asoutline: none
to delete the blue box.Try this:
Update
<input type='number'>
which can adjust the rootfont-size: 8px
to84px
.Relevant Points
z-index: -1
) which has a pseudo-class::after
with thecontent
value of 6 underscores.Both input and overlay must have the following properties:
The overlay is
display: table
and the input isdisplay: table-cell
. This (along withabsolute
andrelative
positioning) keeps the input rigidly centered in the overlay.rem
units are used so if you want to scale thefont-size
up or down, just change thefont-size
of the<html>
tag and everything adjusts accordingly:Demo
Note: Try keeping a key pressed continuously, and you'll see that there's no shifting.
You can place an element containing "the mask" behind the input and set the background color of input to transparent. But pay attention to the following details:
_
and•
is always the same.monospace
so that OS can choose a fixed width font if all of the specified fonts are unavailable.medium
size could be computed as 13px instead of the usual 16px andnormal
line height is often off by 1px for two different fonts having same size). So make sure you specify these properties explicitly.Here is the result:
This conventional solution may help for cross browser :
The HTML form :
We can see the result on input name = real_code. It must be type = 'hidden' on production. Change this maxlength when more field is required.
Style CSS :
Script part :