I'm using the floating labels example from Bootstrap but can not get it to work for the "select" element. I'd like the label for the "select" element to function the same way as the "input".
Asked
Active
Viewed 7,733 times
1 Answers
3
you can use (1)Propeller Select lib or (2)Pure CSS.... Follow Example:
(1)
<div class="form-group pmd-textfield pmd-textfield-floating-label">
<label for="propeller-select">Select with Floating Label</label>
<select id="propeller-select" class="form-control">
<option></option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
</div>
(2)
-HTML-
<div class="floating-label">
<select class="floating-select" onclick="this.setAttribute('value', this.value);" value="">
<option value=""></option>
<option value="1">Item1</option>
<option value="2">Item2</option>
<option value="3">Item3</option>
<option value="4">Item4</option>
<option value="5">Item5</option>
</select>
<label>Select</label>
</div>
-CSS-
.floating-label {
position:relative;
margin-bottom:20px;
}
.floating-select {
font-size:14px;
padding:4px 4px;
display:block;
width:100%;
height:30px;
background-color: transparent;
border:none;
border-bottom:1px solid #757575;
}
.floating-select:focus {
outline:none;
border-bottom:2px solid #5264AE;
}
label {
color:#999;
font-size:14px;
font-weight:normal;
position:absolute;
pointer-events:none;
left:5px;
top:5px;
transition:0.2s ease all;
-moz-transition:0.2s ease all;
-webkit-transition:0.2s ease all;
}
.floating-select:focus ~ label , .floating-select:not([value=""]):valid ~ label {
top:-18px;
font-size:14px;
color:#5264AE;
}
/* active state */
.floating-select:focus ~ .floating-select:focus ~ {
width:50%;
}
*, *:before, *:after {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
/* active state */
.floating-select:focus ~ {
-webkit-animation:inputHighlighter 0.3s ease;
-moz-animation:inputHighlighter 0.3s ease;
animation:inputHighlighter 0.3s ease;
}

Bruno Araujo
- 435
- 4
- 15