Created
August 16, 2018 14:49
-
-
Save darkmavis1980/45c27cb44ea71c8cb7aa210735c29bc8 to your computer and use it in GitHub Desktop.
Placeholder move on focus
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
<!-- | |
# found here https://stackoverflow.com/questions/35942247/how-to-move-placeholder-to-top-on-focus-and-while-typing | |
--> | |
<h1>The floating label</h1> | |
<div class="user-input-wrp"> | |
<br/> | |
<input type="text" class="inputText" required/> | |
<span class="floating-label">Your email address</span> | |
</div> |
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
.user-input-wrp { | |
position: relative; | |
width: 50%; | |
} | |
.user-input-wrp .inputText{ | |
width: 100%; | |
outline: none; | |
border:none; | |
border-bottom: 1px solid #777; | |
} | |
.user-input-wrp .inputText:invalid { | |
box-shadow: none !important; | |
} | |
.user-input-wrp .inputText:focus{ | |
border-color: blue; | |
border-width: medium medium 2px; | |
} | |
.user-input-wrp .floating-label { | |
position: absolute; | |
pointer-events: none; | |
top: 18px; | |
left: 10px; | |
transition: 0.2s ease all; | |
} | |
.user-input-wrp input:focus ~ .floating-label, | |
.user-input-wrp input:not(:focus):valid ~ .floating-label{ | |
top: 0px; | |
left: 10px; | |
font-size: 13px; | |
opacity: 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment