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
"Simple floating input labels"
Bootstrap 4.1.1 Snippet by
bbbenji
4.1.1
Preview
HTML
CSS
View Full Screen
Fork
Fork this
3.0K
 
0 Fav
Post to Facebook
Tweet this
<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <!------ Include the above in your HEAD tag ----------> <div class="container"> <div class="row"> <div class="form-label-group col-sm-6"> <input type="text" class="form-control" placeholder="First name"> <label>First Name</label> </div> <div class="form-label-group col-sm-6"> <input type="text" class="form-control" placeholder="Last Name"> <label for="home-lname">Last Name</label> </div> </div> </div>
.container { max-width: 500px; margin: 2rem auto; } .form-label-group { position: relative; margin-bottom: 1rem; } .form-label-group > input, .form-label-group > label { padding: 0.4rem; } .form-label-group > label { position: absolute; top: 0; left: 0; display: block; width: 100%; font-size: 1rem; line-height: 1.5; pointer-events: none; cursor: text; /* Match the input under the label */ border: 1px solid transparent; border-radius: 0.25rem; transition: all 0.1s ease-in-out; padding-left: 1.4rem; } .form-label-group input:not(:placeholder-shown) { padding-top: 1rem; padding-bottom: 0.25rem; } .form-label-group input:not(:placeholder-shown) ~ label { padding-top: 0.25rem; padding-bottom: 0.25rem; font-size: 10px; } .form-label-group input::-webkit-input-placeholder { color: transparent; } .form-label-group input:-ms-input-placeholder { color: transparent; } .form-label-group input::-ms-input-placeholder { color: transparent; } .form-label-group input::-moz-placeholder { color: transparent; } .form-label-group input::placeholder { color: transparent; } /* Fallback for Edge -------------------------------------------------- */ @supports (-ms-ime-align: auto) { .form-label-group > label { display: none; } } /* Fallback for IE -------------------------------------------------- */ @media all and (-ms-high-contrast: none), (-ms-high-contrast: active) { .form-label-group > label { display: none; } }
Questions / Comments:
Post
Posting Guidelines
Formatting
- Now
×
Close
Donate
BTC: 12JxYMYi6Vt3mx3hcmP3B2oyFiCSF3FhYT
ETH: 0xCD715b2E3549c54A40e6ecAaFeB82138148a6c76