Tips for creating a dynamically responsive eye icon placement

When the screen width is less than 991px, the content is centered but the eye icon that is absolutely positioned goes off-center. This issue only occurs on devices with a small or medium screen size.

The reason for using absolute positioning on the icon is to prevent it from moving. The original code had a functionality to hide and show the password causing the icon to move based on the text length.

.card-plans {
   -webkit-box-shadow: 0px -2px 5px 0px rgba(217,214,217,1);
   -moz-box-shadow: 0px -2px 5px 0px rgba(217,214,217,1);
    box-shadow: 0px -2px 5px 0px rgba(217,214,217,1);
    transition: 0.3s;
    border: 1px solid grey;
  }
  
  .container-plans {
    padding: 5px 28px 5px 28px !important;
  }

  .cred-title {
    text-align: center;
    font-size: 20px !important;
    font-weight: bold;
  }

  .details {
    font-size: 16px !important;
  }

  .details:not(:last-of-type) {
    margin-bottom: 10px !important;
  }


.current-plan {
font-size: 18px;
background: yellowgreen;
padding: 3px 15px;
display: inline-block;
}

.e {
  margin-top: 50px;
  margin-bottom: 20px;
}


.pass {
  cursor: pointer;
}
.stars {
  position: relative;
  top: 0.45ex;
}

.x {
  position: absolute;
  /* top: 78px; */
  left: 300px;
}

.card-plans {
  border-radius: 10px;
}

    
@media only screen and (max-width: 991px)  {
.center {
  margin: 0 auto;
  text-align: center;
}
.x {
  position: absolute;
  left: 600px;
} 
}
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<div class="e">
          <div class="row">
              <div class="col-sm-12 col-md-6 col-lg-5 col-lg-offset-1">
                  <div class="card-plans">
                    <div class="container-plans">
                      <br>
                      <p class="cred-title">Credentials</p><br>
                     <div class="center">
                      <p class="details"><strong>Username:</strong>&nbsp;Joha Lee</p>
                      <p class="details"><strong>Password:</strong>&nbsp;
                        <span class="stars">****************************</span>
                        <i class="x fa fa-eye" aria-hidden="true"></i> 
                       </p>
                        <br>
                        </div>
                      </div>
                     
                  </div>
                </div>
                <div class="col-sm-12 col-md-6 col-lg-5">
                  <div class="card-plans">
                    <div class="container-plans">
                      <br>
                      <p class="cred-title">Current Plan </p><br>
                      <div class="center">               
                      <p class="details"><strong>Type:</strong>&nbsp; Dxx Emails</p>
                      <p class="details"><strong>Plan Cost:</strong>&nbsp; 3332/ Month
                      </p>
                       <br>
                     </div>
                    </div>
                  </div>
                </div>
          </div>
</div>

Answer №1

For proper positioning with absolute, it's essential to have a reliable relative element. I strategically positioned the eye icon within the password field and ensured its relative position, eliminating the need for media queries.

.card-plans {
   -webkit-box-shadow: 0px -2px 5px 0px rgba(217,214,217,1);
   -moz-box-shadow: 0px -2px 5px 0px rgba(217,214,217,1);
    box-shadow: 0px -2px 5px 0px rgba(217,214,217,1);
    transition: 0.3s;
    border: 1px solid grey;
  }
  
  .container-plans {padding: 5px 28px 5px 28px !important;}
  
  .cred-title {
    text-align: center;
    font-size: 20px !important;
    font-weight: bold;
  }
  
  .relative {position: relative;}

  .details {font-size: 16px !important;}

  .details:not(:last-of-type) {margin-bottom: 10px !important;}


  .current-plan {
    font-size: 18px;
    background: yellowgreen;
    padding: 3px 15px;
    display: inline-block;
  }

  .e {margin-top: 50px; margin-bottom: 20px;}

  .pass {cursor: pointer;}
  .stars {position: relative; top: 0.45ex;}

  .x {position: absolute; right: -25px;}

  .card-plans {border-radius: 10px;}

    
@media only screen and (max-width: 991px)  {
.center {margin: 0 auto; text-align: center;}
.x {position: absolute; right: -25px;} 
}
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<div class="e">
          <div class="row">
              <div class="col-sm-12 col-md-6 col-lg-5 col-lg-offset-1">
                  <div class="card-plans">
                    <div class="container-plans">
                      <br>
                      <p class="cred-title">Credentials</p><br>
                     <div class="center">
                      <p class="details"><strong>Username:</strong>&nbsp;Joha Lee</p>
                      <p class="details"><strong>Password:</strong>&nbsp;
                        <span class="stars relative">****************************<i class="x fa fa-eye" aria-hidden="true"></i></span>
                         
 
                       </p>
                        <br>
                        </div>
                      </div>
                     
                  </div>
                </div>
                <div class="col-sm-12 col-md-6 col-lg-5">
                  <div class="card-plans">
                    <div class="container-plans">
                      <br>
                      <p class="cred-title">Current Plan </p><br>
                      <div class="center">               
                      <p class="details"><strong>Type:</strong>&nbsp; Dxx Emails</p>
                      <p class="details"><strong>Plan Cost:</strong>&nbsp; 3332/ Month
                      </p>
                       <br>
                     </div>
                    </div>
                  </div>
                </div>
          </div>
</div>

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

The mdb navigation bar seems to constantly change its height

Having an issue with the height of my mdb navbar in my Angular app. It randomly flips to a larger size when reloading the page, but returns to normal when I open the developer console in Chrome. Two screenshots show the correct display and the incorrect i ...

Create a customized HTML popup featuring various packages

I am struggling to create an HTML popup within a React component due to some errors Here is the code snippet: <div> <button class="toggle">Button</button> <div id="link-box"> <ul> ...

Display the contents of a <div> tag from one HTML file onto another HTML file

Recently I embarked on learning HTML and came across a peculiar doubt. My goal is to create a section div on the first page that changes dynamically based on the menu item clicked, rather than redirecting to another HTML page. I've experimented with s ...

Transition delays in Tailwind CSS when dark mode is activated

My dark mode toggle is functioning with the following CSS: :root { --primary: var(--white); } .dark { --primary: var(--black); } However, when I include the following code: * { @apply transition-colors duration-700; } The background colors of ...

Can the arrangement of icons/buttons on the JW Player control bar be customized?

I am trying to customize the skin of my JWplayer like this: This is my current progress: I have been researching how to rearrange the order of icon / button on the controlbar. According to the jwplayer documentation, the buttons on the controlbar are div ...

Can the current website navigation be integrated into the blog script?

People might see me as a spoil sport for not using Wordpress, but I prefer a flatfile blog system for my small site. Currently, I am using the ozjournals-3.2 blog system. I need assistance in installing a header and site navigation on top of the blog page ...

What could be causing my sticky positioning to not function properly when I scroll outside of the designated

My website is organized into sections, with each section corresponding to a hyperlink in the navigation menu. I've applied the CSS property position: sticky to my navbar, which works as expected within the section bounds. However, I want my red navbar ...

Center the R Shiny showNotification on the screen

Currently, I'm exploring ways to customize the feature of showNotification() in Shiny. Link to example notifications My goal is to have the message appear at the center of the screen instead of the bottom-right corner. While it doesn't seem pos ...

Using HTML, CSS, and jQuery to add a power sign to an input text box

Is there a way to enter square root and squared symbols into an input box using a calculator with buttons? When clicking a button, the value will be shown in the input box. For example, expressions like x²+x³ or 2√13 + 3√4. I'm primarily concern ...

Integrate stylish checkbox design into a form in Rails

I discovered some beautiful css styles for checkboxes that I would like to use instead of the regular ones. You can find these styles here: . Could someone guide me on how to implement this change? This is the code snippet from the form: <div class=" ...

Is there a copyright concern regarding CSS?

There are countless websites that spark my creativity. If I am inspired by a particular design, CSS, or JavaScript on one of these sites, am I allowed to copy it to my local folder and use it? For instance, let's say I come across a website called xy ...

Adjust size of element in relation to Background Cover using jQuery

Can you help me solve a challenge I'm facing? I have a website with a fullsize background image, and I need to attach a div to a specific position on the image while ensuring that it scales in the same way as the background image with the "background ...

Troubleshooting challenges arise with Bootstrap's button group spacing issue

I am encountering spacing issues with the markup provided below. <h2>Profitability Report</h2> <form method="post"> <div class="row"> <div class="col-md-12"> <div class="btn-group btn-group-toggle ...

Vue 3's Paged.js does not respond to requests for page breaks

Currently, I'm working on implementing page breaks in Vue.js 3. Despite my efforts and utilization of the specified CSS code, I am facing challenges with the ".page-break" class parameter. While I can successfully modify other elements like titlePage ...

What could be causing the issue with my linear gradient not displaying correctly on top of my background image in Rails and Sass?

I am struggling to get a linear gradient to display over a background image. Despite trying various solutions from other questions, I still can't get it to work with my current code... .bottom-pic { width: 100%; height: 425px; ...

Specifying Size of Icons in HTML and CSS

Displayed in the image below are 3 icons - 2 of them are the same size, while one (on the left) appears larger and uneven compared to the other two. https://i.sstatic.net/JtIov.png This snippet demonstrates the HTML code related to this section: < ...

The CSS float is positioned beneath the Bootstrap navigation bar

Having an issue with the menu bars in my Rails 4 app. Specifically, I'm struggling with two divs overlapping. The goal is to align the "Register" and "Log In" blocks with the left-hand side menu while floating right. It should not float slightly belo ...

Create widget that is resistant to inherited traits

In our development process, we are crafting a widget designed to be seamlessly integrated into external websites. This integration involves the dynamic injection of a div element within the body of the page using Javascript. While the widget appears satis ...

Tips for hiding text on hover effect

I'm currently working on a menu where each item displays text that is replaced by an email address on hover. However, I am struggling to remove the text during the hover state. Below is the code I have written so far: #home { font: 30px 'Le ...

Creating animated effects through Javascript and CSS triggered by user events

As a beginner in javascript and CSS, I am experimenting with creating a simple animation that adjusts the transparency of an image when triggered by an event. However, I am facing an issue where the animation only works every other time the function is cal ...