search

Home  >  Q&A  >  body text

CSS translation not applied

I need to center my eye icon with my login form input. However, my Top 50% and Translation properties seem to be applied to the main field class instead of inside the input. Therefore, the icon is not aligned within the input field.

.form .field {
  position: relative;
  height: 70px;
  width: 100%;
  margin-top: 24px;
  border-radius: 3px;
}

.field input, .field button {
  height: 70%;
  width: 100%;
  border: none;
  font-size: 14px;
  font-weight: 400;
  border-radius: 3px;
}

.field input {
  outline: none;
  padding: 0 15px;
  border: 1px solid#CACACA;
}

.eye-icon {
  position: absolute;
  top: 50%;
  right: 10px;
  transform: translateY(-50%);
  font-size: 18px;
  color: #8b8b8b;
  cursor: pointer;
  padding: 5px;
}
<div class="field input-field">
  <label for="login-pwd">Password</label>
  <input type="password" name="password" class="form-control" placeholder="Password" id="login-pwd" required="">
  <i class="bx bx-hide eye-icon" id="toggle-password"></i>
</div>

Can someone help me solve this problem? I want my icon to be in the center of the input type password.

P粉441076405P粉441076405442 days ago522

reply all(1)I'll reply

  • P粉841870942

    P粉8418709422023-09-12 21:26:28

    You need to give the parent element position:relative;

    .input-field {
     position: relative;
    }

    reply
    0
  • Cancelreply