【问题标题】:Placing password visibility icon inside password field在密码字段内放置密码可见性图标
【发布时间】:2021-12-22 17:47:34
【问题描述】:

我有以下代码。

<div class="login-password">
              <label for="password" class="form-label"
                >Enter your password</label
              >
              <input
                id="loginPassword"
                type="password"
                class="form-control"
                placeholder="Enter your password"
              />
              <i
                class="bi bi-eye-slash"
                id="togglePassword"
                style="margin-left: -30px; cursor: pointer"
              ></i>
</div>

当我这样做时,密码可见性图标如下图所示。

如何在密码字段中放置可见性图标。

【问题讨论】:

    标签: javascript html passwords toggle


    【解决方案1】:

    以marketwatch.com 的登录为例,您必须将 标签的css 属性“位置”设置为“绝对”。这将允许您将其放置在输入框中。也许是这样的:

    .bi-eye-slash {
        width: 25px;
        height: 25px;
        position: absolute;
        z-index: 200;
        top: 28px;
        right: 10px;
        cursor: pointer;
    }
    

    【讨论】:

    • 感谢您的回复,但这对我不起作用。无论如何,我找到了我的问题的答案并将其发布在下面
    【解决方案2】:

    我找到了自己问题的答案。好吧,我们要对输入进行分组,图标是这样做的,下面是代码。

    .input-group-addon i {
        margin-left: -30px;
        cursor: pointer;
        z-index: 200;
        position: absolute;
        font-size: large;
        color: #6c757d;
      }
     <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.3.0/font/bootstrap-icons.css"
    />
    
    <div class="login-password">
                      <label for="password" class="form-label"
                        >Enter your password</label
                      >
                      <div class="input-group">
                        <input
                          id="loginPassword"
                          type="password"
                          class="form-control"
                          placeholder="Enter your password"
                        />
                        <div class="input-group-addon">
                          <i class="bi bi-eye-slash" id="togglePassword"></i>
                        </div>
                      </div>
                    </div>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-04
      • 1970-01-01
      • 2022-09-28
      • 1970-01-01
      • 1970-01-01
      • 2010-12-25
      • 2016-01-07
      • 2017-05-27
      相关资源
      最近更新 更多