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

What causes block elements to act like inline elements?

:target { border: 2px solid #D4D4D4; background-color: #e5eecc; } .navigation li { list-style-type: none; float: left; padding: 1em; } <ul class="navigation"> <li> <a href="#help"> Help </a> </li> <li> & ...

I have configured my CSS styles in the module.css file of my Next.js application, but unfortunately, they are not being applied

I recently developed a nextjs with electron template application: Here is the link to my code on CodeSandbox: https://codesandbox.io/s/sx6qfm In my code, I have defined CSS classes in VscodeLayout.module.css: .container { width: '100%'; he ...

What is the best way to apply "display: none;" on a span element nested within a title attribute?

I am utilizing the social-share-button gem to share blog posts on social media. The website has been internationalized, making it bilingual (English and German). Everything is functioning correctly, but I encounter an issue with the social share buttons wh ...

The process involves transferring information from a specific div element to a database. This particular div element obtains its data after receiving an appended ID

It's a bit complicated, but I'm working on creating a tag system. I'm fetching data from a database with an AJAX call using the "@" symbol. Everything is working fine - the tags are being generated, but I'm having trouble retrieving and ...

Tips for adjusting the scrollbar in Tailwind (next.js/react)

Having trouble changing the appearance of my scrollbar in a single page application using Tailwind (react/next). I've attempted to create custom CSS for the first div in my index file, like so: <div className="no-scroll"> <<< ...

Show using foreach, with a modification of the spacing between rows and columns

For my project, I need to display the same image 24 times with a 3x8 matrix on an A4 size page using a foreach method. The issue I'm encountering is that I have to manually add space between each row and column, but it cannot cause the page to break. ...

What is the appropriate conversion for a CSS property name starting with -webkit when working with React?

For example, using `-webkit-text-fill-color` resulted in an error when setting it to `'red'`, stating "Using kebab-case for CSS properties in objects is not supported. Did you mean WebkitTextFillColor?" I have attempted `WebkitTextFillColor`, `w ...

Exploring the font variables in the asset pipeline of Rails 7

Creating a habit of defining a set of root variables is crucial for maintaining consistency throughout an application. :root { --main-font-family: "Helvetica Neue", Helvetica, Roboto, Arial, sans-serif; --kbd-font-family: Consolas, "Libe ...

Having trouble identifying the specific CSS property that is being used or inherited

I have incorporated components from Twitter Bootstrap CSS into a custom CSS file, focusing mainly on toolbar components. Specifically, I have set up a toolbar with various features. However, when applying additional CSS to the .signinbox_left:hover select ...

Problem with Internet Explorer version 9 and above and the Flip Card feature

I have a cool feature for one of my clients where clicking on one div causes another div to flip in its place, like a card flipping over. It's kind of like those portfolio image flippers, but instead of images, it flips divs with content inside. How ...

Making lightbox/dhtml appear in front of flash

After extensive research, I have come across numerous posts highlighting the importance of modifying the embed-tag with wmode="opaque" in order to force lightbox and other dhtml elements above flash content. Simply adjusting the z-index of the desired elem ...

Why @font-face doesn't display on older versions of Internet Explorer like IE 7 and IE

Our website has the following CSS code. The use of a smiley face is to ensure compatibility with IE 7 and IE 8. However, while the site's fonts display correctly on IE 9, Chrome, Firefox, etc., there seems to be an issue with IE 7 and 8. @font-face { ...

Design a food selection with only CSS and HTML

I am working with a menu structure that looks like this: <ul class"menu"> <li> <a>item1</a> <ul> <li><a>subitem1</a></li> <li><a>subitem2</a></li> &l ...

How can I create a single-page application that adjusts to different screen sizes effortlessly?

I am working on developing a single-page application that fits within one screen with the following structure: There is a fixed header that includes: Two columns (1/3 for left, 2/3 for right) : a logo on the left a breadcrumb on the right. The ...

What is the solution to prevent the inadvertent activation of onmouseEnter when onmouseLeave

I recently created a CSS/Jquery script that enlarges a DIV and replaces a font awesome icon with some text when hovered over, then changes it back to the icon when the mouse leaves. However, I noticed in the console that when I remove the mouse from the DI ...

When incorporating Transify, don't forget to apply the border-radius property to enhance

I found a solution to make a div semi-transparent using Transify, but I also want to add rounded edges. The issue I'm facing is that the rounded edges only appear after the page has fully loaded when using Transify. Here is the CSS code: .grid { ...

Tips for modifying hover effects using jQuerystylesheet changes

I attempted running the following code snippet var buttonElement = $('<button>Button</button>'); $('body').append(buttonElement); buttonElement.hover().css('background-color', 'red'); Unfortunately, the ...

Select any menu option to return to the one-page layout and then scroll down to find the location

I'm wondering if there is a way to navigate back from an external page to a specific section on my one-page website with a fixed menu? On my one-pager website, I have a fixed menu that includes a "apply for a job" button. When clicked, it takes users ...

Text centered on hover for figure caption

Check out this fiddle http://jsfiddle.net/sLdhsbou/ where I am trying to center the "x" that appears on hover perfectly no matter what size the image is. Also, why does the transition not occur when moving the mouse outside of the figure, unlike when movi ...

On mobile devices, a height of 100vh exceeds the visible screen area

Struggling to cover the entire visible part of the browser window using 100vh due to issues on certain devices and mobile browsers. For example, in Safari, the URL section hides a top part, and similarly on some Android devices using Chrome. https://i.stac ...