I have the below CSS for an 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;
height: 20px;
width: 150px;
border-bottom: 2px solid #FFD800;
border-top: 0px;
border-right: 0px;
border-left: 0px;
background-color: #E2E2E2;
color: dimgray;
}
input[type=text], input[type=password]:focus {
height: 30px;
width: 200px;
animation-name: smooth;
background-color: #FFD800;
animation-duration: 0.5s;
animation: smooth 0.5s forwards;
color: black;
}
<div class="body">
<form action="" autocomplete="off" method="POST">
<br><br><h2 align="center">Login</h2><br>
<input type="text" placeholder="Username" name="Username"><br><br>
<input type="password" placeholder="Password" name="Password"><br><br>
<input type="submit" value="submit" name="submit">
</form>
</div>
However, only the password
field looks as it should.
Here is a snippet of what I see
Please advise. Thank you.
Assigning multiple labels to the same form field can cause problems for some combinations of screen readers and browsers, and the results are inconsistent from one combination to the next. Some combinations will read the first label. Some will read the last label. Others will read both labels.
The Boolean readonly attribute, when present, makes the element not mutable, meaning the user can not edit the control. If the readonly attribute is specified on an input element, because the user can not edit the input, the element does not participate in constraint validation.
No. CSS is a presentation language. It cannot be used to alter the semantics and structure of a document. The closest you could come would be to determine which if a file and date input were visible in the document.
The maxLength property sets or returns the value of the maxlength attribute of a password field. The maxlength attribute specifies the maximum number of characters allowed in a password field. Tip: To set or return the width of a password field, in number of characters, use the size property.
Welcome to Stack Overflow and great first question including code.
You're missing the :focus
on input[type=text]
to add the styling when focusing on text input.
Change
input[type=text],
input[type=password]:focus
to
input[type=text]:focus,
input[type=password]:focus
and it will work.
Working example:
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;
height: 20px;
width: 150px;
border-bottom: 2px solid #FFD800;
border-top: 0px;
border-right: 0px;
border-left: 0px;
background-color: #E2E2E2;
color: dimgray;
}
input[type=text]:focus,
input[type=password]:focus {
height: 30px;
width: 200px;
animation-name: smooth;
background-color: #FFD800;
animation-duration: 0.5s;
animation: smooth 0.5s forwards;
color: black;
}
<div class="body">
<form action="" autocomplete="off" method="POST">
<br><br>
<h2 align="center">Login</h2><br>
<input type="text" placeholder="Username" name="Username"><br><br>
<input type="password" placeholder="Password" name="Password"><br><br>
<input type="submit" value="submit" name="submit">
</form>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With