0

I am trying to add CSS to the following HTML form:

input[type=text],
input[type=password] {
  transition: height 0.4s ease-in-out, width 0.4s ease-in-out, background 0.4s ease-in-out;
  padding: 18px;
  color: dimgray;
}

input[type=text],
input[type=password] :focus {
  animation-name: smooth;
  background-color: #FFD800;
  color: black;
}
<form action="dashboard.php" autocomplete="off" method="POST">

  <br><br>
  <h2 align="center">Login</h2><br>
  <input type="password" placeholder="Username" name="Username"><br><br>
  <input type="password" placeholder="Password" name="Password"><br><br>
  <input type="submit" value="Submit">

</form>

The CSS works for input type="text" but not input type="password". Please advise.

Thank you!

5
  • This has nothing to do with php , I've removed the tag. Commented Dec 10, 2020 at 7:27
  • Sorry, that's an extra bit of code I had copied in. Any suggestions as to my question? Thank you! Commented Dec 10, 2020 at 7:28
  • I would say you didn't arrange your code well Commented Dec 10, 2020 at 7:29
  • Can you be more descriptive for your issue. Which css is not working? Commented Dec 10, 2020 at 7:30
  • Can you consider to add Snippet? Commented Dec 10, 2020 at 7:30

3 Answers 3

3

Check this now, you have un necessary space between input[type=text], input[type=password] and :focus which was the issue that focus css was not applying:

  input[type=text], input[type=password]  {
        transition: height 0.4s ease-in-out, width 0.4s ease-in-out, background 0.4s ease-in-out;
        padding: 18px;
        color: dimgray;
    }
    input[type=text], input[type=password]:focus {
        animation-name: smooth;
        background-color: #FFD800;
        color: black;
    }
<form action="dashboard.php" autocomplete="off" method="POST">
                    
    <br><br><h2 align="center">Login</h2><br>
    <input type="password" placeholder="Username" name="Username"><br><br>
    <input type="password" placeholder="Password" name="Password"><br><br>
    <input type="submit" value="Submit">
            
</form>

Working Fiddle

Sign up to request clarification or add additional context in comments.

2 Comments

Solved! Thank you!
Done, I've marked it as accepted! Thank you for your time!
0

Firstly, change the User input to "text" type. Secondly, remove space between the input[type=text], input[type=password] and :focus elements over CSS.

  input[type=text], input[type=password]  {
        transition: height 0.4s ease-in-out, width 0.4s ease-in-out, background 0.4s ease-in-out;
        padding: 18px;
        color: dimgray;
    }
    input[type=text]:focus, input[type=password]:focus {
        animation-name: smooth;
        background-color: #FFD800;
        color: black;
    }
<form action="dashboard.php" autocomplete="off" method="POST">
                    
    <br><br><h2 align="center">Login</h2><br>

    <!--  change type from "password" to "text"  -->
    <input type="text" placeholder="Username" name="Username"><br><br>                                   
    <input type="password" placeholder="Password" name="Password"><br><br>
    <input type="submit" value="Submit">
            
</form>

2 Comments

Removing the space solved the issue. Thank you!
Kindly tick the answer which has solved your issue. Thanks.
-1

try this

input[type=text],
input[type=password]  {
    transition: height 0.4s ease-in-out, width 0.4s ease-in-out, background 0.4s ease-in-out;
    padding: 18px;
    color: dimgray;
} 

input[type=text]:focus, 
input[type=password]:focus {
    animation-name: smooth;
    background-color: #FFD800;
    color: black;
}

2 Comments

Using only try this doesn't help the OP... add some explanation please
just some spacing issue. not big deal

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.