Created
January 10, 2023 15:45
-
-
Save adrianbrowning/9afb5246a1e164d37ac6bce0e2e764ff to your computer and use it in GitHub Desktop.
Input Fields — Interactive, Animated, Validated
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <form> | |
| <fieldset> | |
| <input | |
| type="text" | |
| placeholder=" " | |
| id="first-name" | |
| minlength="5" | |
| required | |
| /> | |
| <label for="first-name">Full name</label> | |
| </fieldset> | |
| </form> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| :root { | |
| --grey: grey; | |
| --red: red; | |
| --green: lightgreen; | |
| } | |
| fieldset { | |
| border: none; | |
| padding: 0; | |
| position: relative; | |
| } | |
| [type="text"] { | |
| font-size: 26px; | |
| border: none; | |
| outline: none; | |
| border-bottom: 3px solid var(--grey); | |
| padding: 5px 0; | |
| transition: border-color 300ms; | |
| } | |
| [type="text"]:focus { | |
| border-color: black; | |
| } | |
| [type="text"] + label { | |
| font-size: 26px; | |
| position: absolute; | |
| left: 0; | |
| top: 0; | |
| color: var(--grey); | |
| } | |
| [type="text"]:focus + label, | |
| input:not(:placeholder-shown) + label { | |
| transform: scale(0.6) translateY(-40px); | |
| } | |
| [type="text"] + label { | |
| font-size: 26px; | |
| position: absolute; | |
| left: 0; | |
| top: 0; | |
| color: var(--grey); | |
| pointer-events: none; | |
| transform-origin: left; | |
| transition: transform 300ms; | |
| } | |
| [type="text"] { | |
| border-bottom: 3px solid var(--grey); | |
| transition: border-color 300ms; | |
| } | |
| [type="text"]:focus { | |
| border-bottom: 3px solid black; | |
| } | |
| [type="text"]:not(:placeholder-shown):not(:focus):invalid { | |
| border-bottom: 3px solid var(--red); | |
| } | |
| [type="text"]:not(:placeholder-shown):not(:focus):valid { | |
| border-bottom: 3px solid var(--green); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment