Created
November 5, 2022 18:13
-
-
Save MohitSharma0101/fa76287999723346aefb4431affda899 to your computer and use it in GitHub Desktop.
Animated Material Input in Pure CSS by ALGOPOINT
This file contains 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
.input-wrapper { | |
--padding: 16px; | |
--focus-color: black; | |
position: relative; | |
display: flex; | |
align-items: center; | |
} | |
input { | |
padding: var(--padding); | |
border: 2px solid gray; | |
outline: none; | |
border-radius: 6px; | |
} | |
.placeholder { | |
position: absolute; | |
background-color: white; | |
color: gray; | |
left: var(--padding); | |
padding: 0 4px; | |
transition: all 0.2s ease-in; | |
} | |
input:is(:focus, :valid) { | |
border: 2px solid var(--focus-color); | |
} | |
input:is(:focus, :valid) + .placeholder { | |
transform: translatey(calc(-1 * var(--padding) - 12px)); | |
font-size: 14px; | |
color: var(--focus-color); | |
} |
This file contains 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
<div class="input-wrapper"> | |
<input type='text' id='input' required ></input> | |
<label | |
for='input' | |
class='placeholder'> | |
Username | |
</label> | |
</div> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment