How to partition input field to appear as separate input fields on screen?

前端 未结 7 1784
半阙折子戏
半阙折子戏 2020-11-29 21:12

Look at the image:

I want design something like in the image, where a 4 digit one time password (OTP) is to be entered by user. Right now I have achieved th

相关标签:
7条回答
  • 2020-11-29 21:59

    I don't know how to split an input in html5, maybe in css you can use the same class to controll your input and you can style input, something like :

    div{
       text-align:center;
       background:#eee;
    }
    input{
        border: 0;
        outline: 0;
        background: transparent;
        border-bottom: 2px solid black;
        width: 100px;
        text-align:center;
        padding : 5px;
        margin-left:10px;
    }
    button{
      margin-top:20px !important;
      margin: 0 auto;
      color: white;
      border-radius: 4px;
      text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
    }
    <div>
        <input class="form-control" placeholder="0" maxlength="1"  />
        <input class="form-control" placeholder="0" maxlength="1"  />
        <input class="form-control" placeholder="0" maxlength="1"  />
        <input class="form-control" placeholder="0" maxlength="1"  />
        <br><button type="button" onclick="myFunction()">Submit</button>
        <p id="optRes"></p>
    </div>    

    Define myFunction() and You can get your array by your class : form-control, convert to string then into int if you have to check it . Helps this ?

    0 讨论(0)
提交回复
热议问题