Placing an eye icon on the password input field for optimal visibility and positioning

I am currently working on a Node.js project and I am attempting to incorporate an eye icon using Bootstrap into the password input field for visibility. Below is the code snippet of my input field:

  <div class="container">
        <form action='/register' method='post'>
            <h1 class="text-center">Enter data for form</h1>
            /* some other fields */
            <div class="form-group input-group">
                <input class="form-control item" type="password" name="password" id="password"
                minlength="8" pattern="^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^\da-zA-Z]).{8,}$" id="password" placeholder="Password" required autocomplete="off">
                <i class="far fa-eye-slash" id="togglePassword"></i>
            </div>
            <div class="form-group text-center">
              <button class="btn btn-primary btn-block save-info"
              type="submit">Register </button>
            </div>
        </form>
   </div> 

The issue lies with the positioning of the eye icon. Below are all the necessary CSS styles:

.container{
    display: flex;
    align-items: center;
    justify-content: center;
  padding:50px 0;
}

.container form, .hello {
  max-width:900px;
  padding:20px 30px;
  border-radius:10px;
  box-shadow:4px 4px 15px rgba(0, 0, 0, 0.2);
  margin: 0 auto;
  background-color: #FFFACD;
}

.container .form-group {
  border-radius:10px;
  margin-bottom:25px;
  padding:5px 10px;
}

.container .save-info {
  border-radius:20px;
  padding:10px 20px;
  font-size:18px;
  font-weight:bold;
  background-color:#3f93ff;
  border:none;
  color:white;
  margin-top:10px;
}


.container .text-center {
  font-size: xx-large;
  color:#154360;
}
 
#togglePassword {
  position: relative;
/*  left: 85%;*/
  cursor: pointer;
  margin-top: 10px;
}

I attempted to use the togglePassword identifier as shown above, but the result was less than ideal with the eye icon appearing awkwardly after the input field. I also experimented with the following code:

#togglePassword {
      position: absolute;
      left: 92%;
      cursor: pointer;
      margin-top: 10px;
    }

However, when I started typing in the password, the eye icon disappeared which indicates faulty logic. Can someone provide a better solution or any suggestions to improve the appearance and functionality of the eye icon for comfortable and user-friendly interaction? The goal is to allow users to click on the eye icon to show/hide their password securely.

Answer №1

If you're struggling with using the bootstrap input group effectively, be sure to include two wrappers with the CSS classes input-group-append and input-group-text around your icon. To place an icon on the right side of your input group, follow this code example (compatible with bootstrap 4):

<div class="form-group">
   <div class="input-group">
      <input type="text" class="form-control" placeholder="Recipient's username" aria-label="Recipient's username">
     <div class="input-group-append">
        <span class="input-group-text">
           <span class="far fa-eye-slash"></span>
        </span>
     </div>
</div>

No need for the CSS code for #togglePassword.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

I am having issues with this knob not updating, and the reason for this problem is unknown to me

Within my PHP code, I am utilizing the following: <?php @include_once('fields.php'); $gg = fetchinfo("val","inf","n","current"); $mm = fetchinfo("val","info","n","max"); $cc = fetchinfo("num","games","id",$gg); $percent = $cc / $mm * 100; ...

The CSS scale property is not working as expected when used in a React.js application, specifically

working environment ・next.js ・react ・typescript https://www.youtube.com/watch?v=ujlpzTyJp-M A Toolchip was developed based on the referenced video. However, the --scale: 1; property is not being applied. import React, { FunctionComponent ...

What could be causing me to receive null when trying to retrieve an element with document.getElementById, even after invoking $(document).ready(function() { ... })?

Here's a small example. I'm feeling a bit rusty with JavaScript, as it's been some time since I last worked with it. The problem I'm encountering is an error in Chrome developer tools: "Uncaught TypeError: Cannot set property 'src ...

I encountered a difficulty in getting my video to play properly on the Safari browser

I am trying to figure out why my video won't play on Safari, even though it works fine on Google Chrome and Edge. https://i.sstatic.net/oZQVo.png Below is a snippet of my HTML code: <video width="640" height="360" controls=&qu ...

Tips for activating a deactivated input field in ReactJS

I am trying to create a feature where my textfields are automatically disabled, but can be enabled for editing by clicking an 'Edit' button. Clicking the button again should disable the textfields and save any edits made. I have experimented with ...

What is the best way to isolate a single element within a for loop and exclude all others?

I have implemented a dynamic Ajax call to compare the string entered in the text field (representing a city name) with the "type" value in a JSON array. As I iterate through the elements of the array, I am checking the values associated with the key "type ...

Retrieve the unique payment ID generated from the database and present it on the frontend

Greetings, I am currently working on integrating a payment processor and I require the automated generation of the corresponding payment ID in the backend. On the frontend side, I have implemented JS to request data from the backend, but I'm facing ...

An issue with the image filter function in JavaScript

I am currently working on a simple application that applies image filters to images. Below is the code I have written for this purpose. class ImageUtil { static getCanvas(width, height) { var canvas = document.querySelector("canvas"); canvas.widt ...

Alert: The attempt to include_once(headerSite.php) has encountered an error as the file does not exist in the specified directory

I'm a beginner in PHP and encountering the following errors: Warning: include_once(headerSite.php): failed to open stream: No such file or directory in C:\xampp\htdocs\dbtest\index.php on line 3 Warning: include_once(): Failed ope ...

I'm just starting out with jQuery and JSON and could use some assistance with formatting the string, specifically so I can properly iterate through it

This is the controller. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> @RequestMapping("/getDropDownAjax") public void fetchData(HttpServletRequest req,HttpServletResponse resp){ System.out.println ...

What folder layout is best suited for organizing Protractor end-to-end test cases?

Is it best practice to maintain the folder structure for e2e test cases in Protractor identical to that of the application? ...

A regular expression in Javascript that can be used to identify at least one word starting with a number among multiple words, with a

Currently, I am utilizing JavaScript Regex to validate an input field based on specific conditions: The value must consist of only alphabets and numbers There should be a minimum of two words (more than two are allowed) Only one word can start with a num ...

Building a stylish table using Material UI in ReactJS

I've been working on creating a dashboard using the Material UI minimized table. You can check out the documentation here: Material UI Tables However, I've encountered an issue that has me stuck for the past 5 hours. While I was able to successf ...

Having trouble decoding a cookie received from a React.js front-end on an Express server

When using React js for my front end, I decided to set a cookie using the react-cookie package. After confirming that the request cookie is successfully being set, I moved on to configure the Express server with the cookie parser middleware. app.use(cookie ...

Vue feature allows users to save favorite films

Welcome to my homepage where I showcase 3 movies taken from the store, each with an "add to fav" button. My goal is to have the selected movie appear on the favorites page when clicked. As a newcomer to Vue, any code or documentation suggestions would be h ...

Transfer the HTML5 FullScreen (MAP) feature onto a separate display

I'm trying to integrate a leaflet map into my AngularJS Application, but I've hit a roadblock. My goal is to move the Fullscreen feature of the Map to a second screen (if one is available), allowing users to interact with the application on the ...

Use AngularJS to extract information from Wikipedia and display it

Just starting out with angularjs and attempting to pull data from Wikipedia to display on the front end. I managed to fetch the data using the php code below: $url = 'http://en.wikipedia.org/w/api.php?action=query&prop=extracts|info&exintro&a ...

Removing a row from a table using a button click in PHP

I am experiencing difficulty passing the ID of the button to delete the corresponding row. What steps should I take to ensure that the ID is passed correctly? <form method="POST" > <table border="1"> &l ...

The React Router's Switch component fails to update when the route is changed

In my component, I have a list of news categories. The links to these categories are in another component within the Router. However, when I change the link, the content does not update. I suspect this is because my NewsFeed component, where I define the S ...

Issue with Bootstrap-vue pagination navigation not functioning correctly (unexpectedly refreshes upon clicking a page)

I recently updated my website's gallery pagination by following a helpful guide. However, I encountered a problem where clicking on a new page number refreshes the entire webpage, unlike the smooth transition shown in the tutorial. This is not the beh ...