Edge and Internet Explorer fail to recognize the :focus CSS selector

I am utilizing CSS to make our placeholders jump up when clicked inside, but Edge is not recognizing the CSS. It works fine on every other browser except for Edge. I've tried various solutions but none seem to work on Edge. Any thoughts on what might be causing this issue?

"I have searched for similar articles here, but none of them are effective on the current version of Edge. I also attempted using : instead of :: at the ms- line, but that did not work either."

input {
    padding:10px;
    width:95%;
  }
 
 
 label {
    margin:10px 0;
    position:relative;
    display:inline-block;
    width:100%;
  }
    
  span {
    padding:10px;
    pointer-events: none;
    position:absolute;
    left:0;
    top:0;
    transition: 0.2s;
    transition-timing-function: ease;
    transition-timing-function: cubic-bezier(0.25, 0.1, 0.25, 1);
    opacity:0.5;
  }

  
  
  input:focus ~ span, input:not(:placeholder-shown) ~ span {
    opacity:1;
    transform:translateY(-100%) translateX(-10px);
    font-size:10px;
    padding:5px 10px;;
    
  }
  
  /* For IE Browsers*/
  
  input:focus ~ span, input:not(:-ms-input-placeholder) ~ span {
    opacity:1;
    transform:translateY(-100%) translateX(-10px);
    font-size:10px;
  }
<label>
     <input type="password" name="E_password" value="" placeholder=" " />
     <span>Password*</span>
</label>  

Answer №1

Upon investigation, I have confirmed that the issue occurs in the MS Edge (EdgeHtml) browser but not in Internet Explorer where your code functions correctly.

To address this problem, I have included some CSS code below specifically tailored to resolve the compatibility issues with the MS Edge (EdgeHtml) browser:

/* For Edge Browser*/

  input:focus ~ span, input:invalid:not(:focus)::-webkit-input-placeholder {
    opacity:1;
    transform:translateY(-100%) translateX(-10px);
    font-size:10px;
  }

Updated code snippet:

<!doctype html>
<html>
<head>
<style>
input {
    padding:10px;
    width:95%;
  }
 
 label {
    margin:20px 0;
    position:relative;
    display:inline-block;
    width:100%;
  }

span {
    padding:10px;
    pointer-events: none;
    position:absolute;
    left:0;
    top:0;
    transition: 0.2s;
    transition-timing-function: ease;
    transition-timing-function: cubic-bezier(0.25, 0.1, 0.25, 1);
    opacity:0.5;
  }  

input:focus ~ span, input:not(:placeholder-shown) ~ span {
    opacity:1;
    transform:translateY(-100%) translateX(-10px);
    font-size:10px;
    padding:5px 10px;;
    
  }

input:focus ~ span, input:not(:-ms-input-placeholder) ~ span {
    opacity:1;
    transform:translateY(-100%) translateX(-10px);
    font-size:10px;
  }

input:focus ~ span, input:invalid:not(:focus)::-webkit-input-placeholder {
    opacity:1;
    transform:translateY(-100%) translateX(-10px);
    font-size:10px;
  }
</style>

</head>
<body>
<label>
     <input type="password" name="E_password" value="" placeholder=" " />
     <span>Password<sup><font color="red" class="imp" >*</font></span>
</label>  
</body>
</html>

Result in MS Edge (EdgeHtml) browser:

https://i.sstatic.net/WPTfK.gif

Result in IE 11 browser:

https://i.sstatic.net/DZnGj.gif

Source:

Floating Label with Css not working in edge, internet explorer

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

Enhance your web design with the mesmerizing jQuery UI drop effect combined

I'm attempting to create an animated toggle effect on a box using jQuery UI's drop feature. However, I've encountered some trouble due to the box having box-sizing: border-box applied which is causing issues with the animation. During the a ...

django is not able to load staticfiles from the statifiles_dirs directory

I have placed my style.css in the directory appname/static/appname/. In my settings.py, this is what I have: STATIC_URL = '/static/' STATICFILES_DIRS = ( os.path.join(BASE_DIR, "static/"), ) When I try to load it in my base.html like t ...

What's the best way to make two buttons appear side by side on a webpage?

I need to have my two buttons, Update and Cancel, displayed next to each other on the same line. Currently, there is a gap between the two buttons as shown in the attached image. Below is the HTML code I am using: <div class="form_block span2"> ...

Having trouble with Bootstrap not hiding on small screens as intended?

I'm not sure if the issue is related to my browser, but I need the first pills-tab to be hidden on small screens and visible on medium to larger screens. The second pills-tab should be visible on small screens and hidden on larger screens. <!D ...

Deactivate the connection button for accessing the database

I'm currently developing a PHP script to establish a connection with a MySQL database. My goal is to deactivate a button and display a spinner image when I click on a submit button to initiate the database connection. Below is the code snippet I have ...

Generating a table with two columns utilizing ng-repeat

I am currently dealing with an array of objects that I need to showcase in a two-column layout. The challenge arises because some columns have more data than others, requiring equi-height rows. Despite utilizing Bootstrap and clearfix in my attempts to di ...

Creating a Border Length Animation Effect for Button Hover in Material-UI

I'm currently exploring Material-UI and trying to customize a component. My goal is to add a 'Border Length Animation' effect when hovering over the button. Unfortunately, I have yet to successfully implement this animation as intended. For ...

Prevent vertical scrolling only on mobile devices while allowing horizontal scrolling

Currently, I am working on a web page that utilizes a horizontal layout. However, when viewing the page on mobile devices, I want to restrict scrolling to only the horizontal direction, preventing users from being able to scroll up or down. As it stands n ...

Position the read more buttons in JavaScript at the bottom of the div

I designed three boxes in this section with content inside. To enhance the functionality, I added a feature that made the boxes smaller. Everything was functioning perfectly, but I encountered an issue with the alignment of the buttons at the bottom. Is th ...

When the mouse is moved to the UL LI list, the border color of the Top Hover is reverted back to default

Can you assist me with this issue? I need to modify the code below so that the border color remains blue while a user selects an item from the UL LI list. Here is an image showing the current problem: And here is a picture of the expected outcome: For ...

Switch between visibility of objects with toggle button

I have set a background image on the body, and positioned a large box, footer, navigation bar, and header above it. In order to add functionality to slide these elements up and down, I've created two buttons with classes 'slideUp' and &apos ...

Ways to incorporate CSS padding into a website displayed in a webView

I have been trying to figure out a way to apply padding-bottom (Custom CSS) to a webpage fetched from RemoteConfig (URL provided). Unfortunately, I do not have direct access to the webpage's source files for editing. Below is the code snippet in ques ...

Sliding a division using Jquery from the edges of the browser's window

<script> $(function(){ $('#right_image1').hide().delay('10000').fadeIn('5000').animate({right: '0'}, 5000); $('#left_image1').hide().delay('10000').fadeIn('5000').a ...

Issue with JQuery addClass functionality in Firefox

I've come across numerous posts on this topic, but none of them have provided a solution. I recently added drag and drop functionality to my website. When I drag an item over a valid container, I add a specific class to it. Here is the HTML for the ...

Creating horizontal card overflow with arrow navigation in Bootstrap 4.5: A step-by-step guide

Using Bootstrap, I've created a snippet that generates an overflow card that can be scrolled horizontally. <div class="container"> {{-- If you look to others for fulfillment, you will never truly be fulfilled. --}} <h4 class="mb- ...

Place the sorting image on the left side of the DataTable header

I am currently using DataTable in my code. The sorting images in the header of the table are on the right side while the labels are on the left, as shown below: https://i.sstatic.net/Bz6EO.jpg However, I would like to switch this arrangement and have the ...

Achieve vertical center alignment of text without using line height or table cells

Looking to add a "toggle" animation on my Teaser, here's the code: .ax { height:60px; width:150px; background:gold; } .caption { position: absolute; left:0; top: 35%; overflow: hidden; right: 0; background-colo ...

Safari iOS does not display any background for Buttons

Encountering an unusual problem with buttons on iOS devices specifically in Safari browser - the background color isn't being applied like it is on Desktop and Android devices. Here are the CSS properties for the button: export const Button = styled.b ...

Tips on increasing the height of an element that is overflowing

When populating my timeline component with dynamically mapped data from an array, I encountered an issue where if I added more data causing the maximum height to be reached, the overflow-y element didn't display all content. Despite trying various sol ...

Positioning a list item on the left side within Chrome by using the

It seems that Chrome is displaying the content incorrectly when I use float: left in a block inside an li element. Check out this JSFiddle link <body> <ol> <li> <div class="input"></div> <div class="te ...