Skip to content

Instantly share code, notes, and snippets.

@beseidel
Created July 20, 2019 20:00
Show Gist options
  • Save beseidel/14ba1ed1f1e8ebee3147898b9c0b4c42 to your computer and use it in GitHub Desktop.
Save beseidel/14ba1ed1f1e8ebee3147898b9c0b4c42 to your computer and use it in GitHub Desktop.
SASS Animated Form Labels
<form class="awesome-form">
<div class="input-group">
<input type="text">
<label>Your Full Name</label>
</div>
<div class="input-group">
<input type="email">
<label>Your Email Address</label>
</div>
<input type="submit">
</form>
$(function(){
$('.awesome-form .input-group input').focusout(function(){
var text_val = $(this).val();
if(text_val === "") {
$(this).removeClass('has-value');
} else {
$(this).addClass('has-value');
}
});
});
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
@import bourbon
body
padding: 100px
-webkit-font-smoothing: antialiased
input
background: none
border: solid 2px #21a1e1
color: #21a1e1
padding: 15px 40px
font-size: 18px
display: inline-block
&:focus,
&:active
outline: none
&[type="text"],
&[type="email"]
border: none
border-bottom: solid 2px #21a1e1
&[type="submit"]
&:active
color: white
background: #21a1e1
.input-group
display: inline-block
margin-right: 20px
position: relative
input
padding: 15px 0px
label
+position(absolute, 50% null null 0px)
+transform(translateY(-50%))
font:
family: $georgia
style: italic
size: 18px
color: #999
pointer-events: none
+transition
input:focus + label,
input.has-value + label
top: -10px
font-size: 12px
color: #aaa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment