Add floating placeholder labels to contact form 7 on focus
<script>
$('.wpcf7 input[type=email],.wpcf7 input[type=date], .wpcf7 input[type=number], .wpcf7 input[type=text],.wpcf7 input[type=tel]').each(function(e){
var placeholder = $(this).attr('placeholder');
$(this).wrap('<div class="inputwrapper"></div>').before('<span>'+placeholder+'</span>');
$(this).on('focus',function(){
var inputContent = $(this).val();
if(inputContent == ''){
$(this).prev().addClass('visible');
}
});
$(this).on('blur',function(){
var inputContent = $(this).val();
if(inputContent == ''){
$(this).prev().removeClass('visible');
}
});
});
</script>
<style>
.inputwrapper {
font-weight: 300;
position: relative;
min-height: 60px;
margin-bottom: 10px;
}
.inputwrapper input {
font-family: inherit;
width: 100%;
height: 45px;
line-height: 30px;
font-size: 16px;
border-radius: 6px;
padding: 0 10px;
position: absolute;
border: 1px solid #ccc;
bottom: 0;
background: #f7f7f8;
}
.inputwrapper input::-webkit-input-placeholder {
color: #999;
}
.inputwrapper input:focus {
outline: none;
background: #fff;
}
.inputwrapper span {
position: absolute;
top: 15px;
font-size: 10px;
font-weight: bold;
color: $color-white;
background: #37cc2c;
text-transform: uppercase;
opacity: 0;
transition: 0.3s ease-in-out;
padding:1px 10px;
}
.inputwrapper span.visible {
top: 0;
opacity: 1;
}
.inputtextareawrapper {
font-weight: 300;
position: relative;
min-height: 115px;
margin-bottom: 10px;
}
.inputtextareawrapper textarea {
font-family: inherit;
width: 100%;
height: 100px!important;
line-height: 30px;
font-size: 16px;
padding: 0 10px;
position: absolute;
bottom: 0;
top:15px;
background: #f7f7f8;
}
.inputtextareawrapper textarea::-webkit-input-placeholder {
color: #999;
}
.inputtextareawrapper textarea:focus {
outline: none;
background: #fff;
}
.inputtextareawrapper span {
position: absolute;
top: 15px;
font-size: 10px;
font-weight: bold;
color: $color-white;
background: #37cc2c;
text-transform: uppercase;
opacity: 0;
transition: 0.3s ease-in-out;
padding:1px 10px;
}
.inputtextareawrapper span.visible {
top: 0;
opacity: 1;
}
</style>