-1

I'm trying to put an icon inside a input box. Here is my code:

<div class="content">
    <div class="modal" style="width: 450px;">
        <div class="modal-header" style="background-color: #f0f0f0; padding: 15px;">
            <span style="color: #a2a4a6; font-size: 22px;">Login</span>
        </div>

        <div class="modal-content" style="background-color: white; padding-top: 20px; padding-left: 25px; padding-right: 25px; padding-bottom: 25px;">
            <form class="frm-login">
                <label for="username">Username</label>
                <input type="text" id="username" name="username" placeholder="Enter your username" style="display: block; border-radius: 5px; font-size: 16px; border: 2px solid #a2a4a6; padding: 13px; margin-top: 15px; margin-bottom: 20px; width: 90%;">

                <label for="password">Password</label>
                <i class="bi bi-eye-slash" id="togglePassword" style="cursor: pointer; position: absolute;"></i>
                <input type="password" id="password" name="password" placeholder="Enter your password" style="display: block; border-radius: 5px; font-size: 16px; border: 2px solid #a2a4a6; padding: 13px; margin-top: 15px; margin-bottom: 20px; width: 90%;">

                <input type="checkbox" id="remember-pass" name="remember-pass" style="margin-top: 10px; margin-bottom: 15px;">
                <label for="remember-pass">Remember password</label>

                <div style="margin-top: 20px; display: flex; align-items: center; justify-content: space-between;">
                    <a href="forgot-pass.php">Forgot Password?</a>
                    <input type="submit" value="Login" style="float: right; cursor: pointer; font-size: 16px; text-transform: uppercase; color: #fff; background-color: #7d4a95; border: 0; border-radius: 5px; padding: 10px;">
                </div>
            </form>
        </div>

        <div class="modal-footer" style="background-color: #f0f0f0; text-align: center; padding-top: 15px; padding-bottom: 15px;">
            <a href="register.php">Need an account? Sign up!</a>
        </div>
    </div>
</div>

I have try using "position: absolute" but it didn't work. Anyone know what is the problem?

  • 1
    I don't see any `position: absolute` in what you have shown us. Please do not just _tell_ us that you tried something, but _show_ what you tried. How else could we possibly figure out where it might have gone wrong? – CBroe Aug 08 '23 at 13:03
  • @CBroe yeah because i removed it from the "i" tag. Let me edit my code. – Veri Virgandra Aug 08 '23 at 13:05
  • @CBroe i have edited my code. Now u can see the position: absolute. – Veri Virgandra Aug 08 '23 at 13:07
  • But not the icon, because the font you are using for those is missing. But putting an `X`as text content into the `i` element, illustrates the issue. You have _only_ added `position: absolute`, but none of `top`, `bottom`, `left` or `right` - so the element will stay in the exact same position, it would have had in normal flow without absolute positioning. – CBroe Aug 08 '23 at 13:09
  • @CBroe so what i should do? I really don't understand what u mean – Veri Virgandra Aug 08 '23 at 13:18
  • Then go and find yourself a beginner tutorial that explains the basics of absolute positioning, please. – CBroe Aug 08 '23 at 13:23

0 Answers0