"Simple floating input labels"
Bootstrap 4.1.1 Snippet by bbbenji

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<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>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
.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 {
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Related: See More


Questions / Comments: