CSS: Create iOS style Pin Password box

后端 未结 6 2293
轮回少年
轮回少年 2021-02-14 03:19

I want to create a html5 input that looks like the iOS enter Pin (on the lock screen).... with 4 input boxes.

How do i achieve this?

6条回答
  •  臣服心动
    2021-02-14 04:00

    Instead of using background-image for this purpose, use four input boxes with their type set to password, and than use jQuery to achieve some more user friendliness, if you don't need that functionality of auto focusing to next field you can simply omit the script out and achieve your style..

    Demo

    input[type=password] {
        padding: 10px;
        border: 1px solid #ffffd;
        width: 50px;
        height: 50px;
        text-align: center;
        font-size: 30px;
    }
    

    jQuery (Optional for auto focus functionality)

    $("input").keyup(function() {
        if($(this).val().length >= 1) {
          var input_flds = $(this).closest('form').find(':input');
          input_flds.eq(input_flds.index(this) + 1).focus();
        }
    });
    

提交回复
热议问题