Floating label css

This bootstrap snippet called "Floating label css" was created to help web designers,
front-end developers and back-end developer save time. Use it in your project and build your app faster,
You can also download the HTML, CSS, and JS code

This is the HTML code for this bootstrap snippet

Copy, paste, change, customize and run the following HTML code to get a result like the one shown in the preview tab

<div class="container">
    <div class="jumbotron">
		<h1>Floating label css</h1>
	</div>
    
    <div class="col-md-5 col-md-offset-1">
		<form role="form"  id="floating-label">
		
			<div class="form-group">
				<label class="control-label">First Name</label>
				<input type="text" class="form-control" />
			</div>

			<div class="form-group">
				<label class="control-label">Last Name</label>
				<input type="text" class="form-control"/>
			</div>
		
		</form>
	</div>

</div>

This is the CSS code for this bootstrap snippet

Copy, paste, change, customize and run the following CSS code to get a result Like the one shown in the preview

body{margin-top:20px;}

#floating-label .form-group {
    									display: flex;
										height: 55px;
									}

									#floating-label .control-label {
										font-size: 16px;
										font-weight: 400;
										opacity: 0.4;
										pointer-events: none;
										position: absolute;
										transform: translate3d(6px, 22px, 0) scale(1);
										transform-origin: left top;
										transition: 240ms;
									}

									#floating-label .form-group.focused .control-label {
										opacity: 1;
										transform: scale(0.75);
									}

									#floating-label .form-control {
										align-self: flex-end;
									}

									#floating-label .form-control::-webkit-input-placeholder {
										color: transparent;
										transition: 240ms;
									}

									#floating-label .form-control:focus::-webkit-input-placeholder {
										transition: none;
									}

									#floating-label .form-group.focused .form-control::-webkit-input-placeholder {
										color: #bbb;
									}
                                    

This is the JS code for this bootstrap snippet

Copy, paste, change, customize and run the following JS code to get a result Like the one shown in the preview

$('.form-control').on('focus blur', function (e) {
    	$(this).parents('.form-group').toggleClass('focused', (e.type === 'focus' || this.value.length > 0));
	}).trigger('blur'); 

Information about this bootstrap snippet

Creator: Srinu Sirigiri

Bootstrap version: 3.3.6

Created: Mar 29th 2016, 06:57

Views: 4.3K

Rated 5/5 based on 1 reviews