Toggle navigation
Bootsnipp
Bootstrap
For
CSS Frameworks
Bootstrap
Foundation
Semantic UI
Materialize
Pure
Bulma
References
CSS Reference
Tools
Community
Page Builder
Form Builder
Button Builder
Icon Search
Dan's Tools
Diff / Merge
Color Picker
Keyword Tool
Web Fonts
.htaccess Generator
Favicon Generator
Site Speed Test
Snippets
Featured
Tags
By Bootstrap Version
4.1.1
4.0.0
3.3.0
3.2.0
3.1.0
3.0.3
3.0.1
3.0.0
2.3.2
Register
Login
"Float label with animation"
Bootstrap 3.0.0 Snippet by
wgarrido
3.0.0
animation
Preview
HTML
CSS
JS
View Full Screen
Fork
Fork this
4.6K
 
1 Fav
Post to Facebook
Tweet this
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script> <script src="//code.jquery.com/jquery-1.11.1.min.js"></script> <!------ Include the above in your HEAD tag ----------> <div class="container"> <div class="row"> <div class="col-lg-12"> <h1>Float Label with animation</h1> <form> <div class="form-group float-label"> <label for="exampleInputEmail1">Email address</label> <input type="email" class="form-control" id="exampleInputEmail1" placeholder="Email"> </div> <div class="form-group float-label"> <label for="exampleInputPassword1">Password</label> <input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password"> </div> <button type="submit" class="btn btn-default">Submit</button> </form> </div> </div> </div>
.float-label .header-label{ position: absolute; pointer-events: none; top: -8px; left: 10px; background-color: #FFF; padding: 0px 5px; font-size: 11px; visibility: visible; opacity: 1; } .float-label label { -webkit-transition: top 0.5s, left 0.5s, font 0.5s; -moz-transition: top 0.5s, left 0.5s, font 0.5s; -o-transition: top 0.5s, left 0.5s, font 0.5s; -ms-transition: top 0.5s, left 0.5s, font 0.5s; position: absolute; left: 8px; font-size: 13.2px; top: 8px; visibility: hidden; opacity: 0; } .form-group.float-label{ margin-bottom: 20px; } .form-group{ position: relative; }
$("form .float-label input").each(function () { var placeholder = $(this).attr('placeholder'); console.log(placeholder) var label = $(this).parent().find("label").text(); if (placeholder === undefined || placeholder === "") { $(this).attr("placeholder", label); } }); //Ajoute ou supprime la class header-label $("form .float-label input").bind("input propertychange", function (e) { if ($(e.target).val() !== "") { $(e.target).parent().find("label").addClass("header-label"); } else { $(e.target).parent().find("label").removeClass("header-label"); } });
Questions / Comments:
Post
Posting Guidelines
Formatting
- Now
×
Close
Donate
BTC: 12JxYMYi6Vt3mx3hcmP3B2oyFiCSF3FhYT
ETH: 0xCD715b2E3549c54A40e6ecAaFeB82138148a6c76